Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 05:04, 14 June 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Bitmap Conversion and Scaling

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: manchb (20 Dec 2007)
Last edited: hamishwillee (14 Jun 2013)



The purpose of this wiki is used to convert a Jpeg Image to a Bitmap. The converted Bitmap is then scaled according to the requirement.

Header Files

#include <ImageConversion.h> //CImageDecoder
#include <Fbs.h> //CFbsBitmap
#include <BitmapTransforms.h> //CBitmapScaler

Link against

LIBRARY mgfetch.lib
LIBRARY bafl.lib
LIBRARY fbscli.lib
LIBRARY efsrv.lib
LIBRARY imageconversion.lib
LIBRARY bitmaptransforms.lib


capability ReadUserData // MgFetch::RunL()

Example code

As the API's for conversion and scaling are Asynchronous requests,
and the requirement is for making this Synchronous as scaling should be started only after conversion is done,
we make use of the "CActiveSchedulerWait" class which makes it possible.

The following code explains its usage.

CActiveSchedulerWait* iScheduler = new (ELeave) CActiveSchedulerWait;
//Starts a new wait loop under the control of the current active scheduler.
//within RunL() call the following code once the request is accomplished
// by checking 'iStatus'
//Stops the scheduling loop owned by this object

The following code is used to convert a Jpeg Image to Bitmap.

"CImageDecoder" class has a API "Convert()" will start decoding an image frame asynchronously.

As its an Asynchronous call, we must derive our class from "CActive" class and call the Convert() API.

Initializing and Issuing Request code

//File session for the imagedecoder
//Open a connection to the File Server
RFs iFileSession;
//Imagedecoder object
CImageDecoder* iDecoder;
//We pass the FileSession instance and the name of the file to be decoded
// It creates a decoder for the image in the named file.
//Retrieve the frame info for a specified frame of the image.
TFrameInfo bmpInfo=iDecoder->FrameInfo();
//CFbsBitmap object
CFbsBitmap* iBitmap;
iBitmap=new(ELeave) CFbsBitmap;
//Creates a bitmap with the specified size and display mode.
//start conversion to bitmap

code to be handled after Issuing Request

delete iDecoder;
iDecoder = NULL;
switch( iState )
case EDecoding:
if( iStatus == KErrNone )
iState = EIdle;
else if(iStatus == KErrUnderflow )
iDecoder->ContinueConvert( &iStatus );
else if ( iStatus == KErrCorrupt )
iState = EIdle;
//Inform about the error
// Unknown error
//Inform about the error...

The following code is used to Scale the Bitmap

CBitmapScaler class has a API Scale() which is used for Scaling the Bitmap.

Its an Asynchronous call, so we must derive our class from CActive class.

Initializing and Issuing Request code

//CFbsBitmap object
CFbsBitmap* iSrcBitmap;
//CBitmapScaler object
CBitmapScaler* iBmpScale;
iBmpScale = CBitmapScaler::NewL();
//This begins the bitmap re-scaling operation.
//iSrcBitmap, The bitmap to be re-scaled.
//This reference is also the target location for the re-scaled bitmap.
//TSize(100,100), the requested target size for the re-scaled bitmap.
iBmpScale->Scale(&iStatus, *iSrcBitmap, TSize(100,100));
//Finally the iSrcBitmap contains the scaled Bitmap.

Example project

This page was last modified on 14 June 2013, at 05:04.
89 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.