Saving Symbian bitmap images to files
Article Metadata
- CJpgSaver illustrates a simplified image saver with which you can save Symbian bitmap images into the JPG files. With this example image saving is implemented by using CImageEncoder::FileNewL() - Api, for saving the bitmap to other types of image files, you could change the MIME type constant used with the FileNewL().
- CImageEncoder also allows saving images to buffers, to change this example to save images to buffers, just change the FileNewL() to be DataNewL() and supply modifiable buffer into the function instead of the filename.
- You could also save images to MBM files by using the Save() function defined in CFbsBitmap, note that this function only saves one image to a file, thus you can not have multiple images in the MBM when using this function.
- You could also save Symbian bitmap images into the stores for more information, check the Dictionary store example
SaveJPG.h
#include <f32file.h>
#include <e32std.h>
#include <gdi.h>
_LIT8(KMimeType,"image/jpeg");
class MImageSavedCallBack
{
public:
virtual void ImageSavedL(const TInt& aError) = 0;
};
class CJpgSaver : public CActive
{
public:
static CJpgSaver* NewL(CFbsBitmap& aBitmap,const TDesC& aFileName,MImageSavedCallBack& aCallBack);
virtual ~CJpgSaver();
protected:
void DoCancel() ;
void RunL() ;
private:
CJpgSaver(CFbsBitmap& aBitmap,MImageSavedCallBack& aCallBack);
void ConstructL(const TDesC& aFileName);
private: //data
CFbsBitmap& iBitmap;
MImageSavedCallBack& iCallBack;
CImageEncoder* iEncoder;
};
SaveJPG.cpp
CJpgSaver* CJpgSaver::NewL(CFbsBitmap& aBitmap,const TDesC& aFileName,MImageSavedCallBack& aCallBack)
{
CJpgSaver* self = new (ELeave) CJpgSaver(aBitmap,aCallBack);
CleanupStack::PushL( self );
self->ConstructL(aFileName);
CleanupStack::Pop();
return self;
}
CJpgSaver::~CJpgSaver()
{
Cancel();
delete iEncoder;
}
CJpgSaver::CJpgSaver(CFbsBitmap& aBitmap,MImageSavedCallBack& aCallBack)
:CActive(EPriorityStandard),iBitmap(aBitmap),iCallBack(aCallBack)
{
}
void CJpgSaver::ConstructL(const TDesC& aFileName)
{
CActiveScheduler::Add( this );
iEncoder = CImageEncoder::FileNewL(CCoeEnv::Static()->FsSession(),aFileName, KMimeType);
iEncoder->Convert( &iStatus, iBitmap);
SetActive();
}
void CJpgSaver::DoCancel()
{
iEncoder->Cancel();
}
void CJpgSaver::RunL()
{
iCallBack.ImageSavedL(iStatus.Int());
}


08 Sep
2009
This article explains how to save symbian bitmap images to files in this they used a class CJpgSaver illustrates a simplified image saver which with you can save Symbian bitmap images into the JPG files.
CImageEncoder also allows saving images to buffers, to change this example to save images to buffers, just change the FileNewL() to be DataNewL and supply modifiable buffer into the function instead of the filename.
this will help to beginners who are at start up
10 Sep
2009
This example merely represents to save your Symbian bitmap images to Jpg file. The API used in the article is CImageEncoder. FileNewL() method of this API is used to perform this task. The task is done in asynchronous way. The code contained in this article also shows the use of active objects.The article also mentions different ways to perform this task.
The article is specially meant for beginners only.