You Are Here:

Community: Wiki

This page was last modified on 2 September 2009, at 15:05.

How to read images to Symbian bitmap

From Forum Nokia Wiki


Reviewer Approved   

The CImage_Reader implementation illustrates how to use CImageDecoder to open and read different types of images and how to convert them to the Symbian bitmap format, which then can be used to draw the image to the screen.

The GetFileType function is used to determine the type of the image file, and if the image type is not recognized by the system it will be indicated by the iError variable. The MImageReadyCallBack callback interface is used to notify of the completion of the image loading.


Image_Reader.cpp

#include <cntfield.h>
#include <cntdef.h>
#include <cntitem.h>
#include <cntfldst.h>
#include <cntdb.h>
#include <COEMAIN.H>
#include <APMREC.H>
#include <APGCLI.H>
 
 
CImage_Reader::CImage_Reader(MImageReadyCallBack& aNotify)
:CActive(0),iNotify(aNotify)
{
}
 
CImage_Reader::~CImage_Reader()
{
Cancel();
delete iFrame;
delete iImageDecoder;
}
 
 
void CImage_Reader::ConstructL(const TDesC& aFileName)
{
CActiveScheduler::Add(this);
 
iImageName.Copy(aFileName);
 
TBuf8<255> ImageType;
GetFileType(aFileName, ImageType);
 
if(ImageType.Length() && iImageName.Length())
{
iImageDecoder = CImageDecoder::FileNewL(CCoeEnv::Static()->FsSession(),aFileName,ImageType);
 
delete iFrame;
iFrame = NULL;
iFrame = new(ELeave)CFbsBitmap();
iFrame->Create(iImageDecoder->FrameInfo(0).iOverallSizeInPixels,iImageDecoder->FrameInfo(0).iFrameDisplayMode);
 
iImageDecoder->Convert(&iStatus,*iFrame,0);
SetActive();
}
else
{
TRequestStatus* status=&iStatus;
User::RequestComplete(status, KErrNotSupported);
SetActive();
}
}
 
void CImage_Reader::GetFileType(const TDesC& aFileName, TDes8& aFileType)
{
TEntry FileEntry;
 
if(CCoeEnv::Static()->FsSession().Entry(aFileName,FileEntry) == KErrNone)
{
TBuf8<255> FileBuffer;
 
if(!FileEntry.IsDir())
{
TInt FileSize = FileEntry.iSize;
 
if(FileSize > 255)
{
FileSize = 255;
}
 
if(CCoeEnv::Static()->FsSession().ReadFileSection(aFileName,0,FileBuffer,FileSize) == KErrNone)
{
RApaLsSession RSession;
if(RSession.Connect() == KErrNone)
{
TDataRecognitionResult FileDataType;
 
RSession.RecognizeData(aFileName,FileBuffer,*&FileDataType);
 
if(FileDataType.iConfidence > aResult.iConfidence)
{
aFileType.Copy(FileDataType.iDataType.Des8());
}
 
RSession.Close();
}
}
}
}
}
 
void CImage_Reader::DoCancel()
{
iImageDecoder->Cancel();
}
 
CFbsBitmap* CImage_Reader::Bitmap()
{
return iFrame;
}
 
 
void CImage_Reader::RunL()
{
iNotify.ImageReadyL(iStatus.Int());
}

Image_Reader.h

#include <e32base.h>
#include <coecntrl.h>
#include <w32std.h>
#include <e32std.h>
#include <cntdef.h>
#include <cntdb.h>
#include <ImageConversion.h>
 
class CFbsBitmap;
 
class MImageReadyCallBack
{
public:
virtual void ImageReadyL(const TInt& aError) = 0;
};
 
class CImage_Reader : public CActive
{
public:
CImage_Reader(MImageReadyCallBack& aNotify);
void ConstructL(const TDesC& aFileName);
~CImage_Reader();
public:
CFbsBitmap* Bitmap();
protected:
void DoCancel();
void RunL();
private:
void GetFileType(const TDesC& aFileName, TDes8& aFileType);
private:
MImageReadyCallBack& iNotify;
CImageDecoder* iImageDecoder;
CFbsBitmap* iFrame;
TFileName iImageName;
};


Related links:

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTalkE3aE4cargeE5fscreenE5fsaverX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx2E2E0000X