×
Namespaces

Variants
Actions

Saving Symbian bitmap images to files

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (23 Mar 2007)
Last edited: hamishwillee (20 Sep 2013)

Introduction

The CJpgSaver example class 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, see Saving settings with Dictionary store

SaveJPG.h

#include <f32file.h>
#include <e32std.h>
#include <gdi.h>
#include <ImageConversion.h>
#include <coemain.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());
}
This page was last modified on 20 September 2013, at 03:45.
55 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×