Namespaces
Variants
Actions

Saving Symbian bitmap images to files

Jump to: navigation, search
Article Metadata

Article
Created: symbianyucca (23 Mar 2007)
Last edited: hamishwillee (12 Jan 2012)
  • 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.

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());
}
This page was last modified on 12 January 2012, at 03:31.
87 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved