Categories: Symbian C++ | S60 | Code Examples | Multimedia | Imaging
This page was last modified 10:35, 23 January 2008.
Bitmap Conversion and Scaling
From Forum Nokia Wiki
Purpose
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
ImageConversion.h //CImageDecoder
Fbs.h //CFbsBitmap
BitmapTransforms.h //CBitmapScaler
Link against
mgfetch.lib bafl.lib fbscli.lib efsrv.lib imageconversion.lib bitmaptransforms.lib
Capabilities
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. iScheduler->Start(); //within RunL() call the following code once the request is accomplished // by checking 'iStatus' if(iStatus==KErrNone) { //Stops the scheduling loop owned by this object iActiveSchedulerWait.AsyncStop(); }
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; iFileSession.Connect(); //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. iDecoder=CImageDecoder::FileNewL(iFileSession,iImageFolder); //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. iBitmap->Create(bmpInfo.iOverallSizeInPixels,bmpInfo.iFrameDisplayMode);//EGray256 //start conversion to bitmap iDecoder->Convert(&iStatus,*iBitmap); SetActive();
code to be handled after Issuing Request
if(iStatus==KErrNone) { if(iDecoder) { delete iDecoder; iDecoder = NULL; } } switch( iState ) { case EDecoding: { if( iStatus == KErrNone ) { iState = EIdle; iActiveSchedulerWait.AsyncStop(); break; } else if(iStatus == KErrUnderflow ) { iDecoder->ContinueConvert( &iStatus ); SetActive(); break; } else if ( iStatus == KErrCorrupt ) { iState = EIdle; //Inform about the error break; } else { // Unknown error //Inform about the error... break; } } default: break; }
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)); SetActive(); //Finally the iSrcBitmap contains the scaled Bitmap.
Example project
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to resize a bitmap with masks? | tntfighter-2002 | General Symbian C++ | 3 | 2002-10-30 04:59 |
| Draw bitmap problem | JackSu | Symbian User Interface | 1 | 2007-09-26 05:55 |
| Displaying of Raw Bitmap data in the Display | gilly_kumar | General Symbian C++ | 2 | 2005-10-10 18:42 |
| 关于16位bmp的显示 | wenstory | Symbian | 1 | 2007-09-07 08:58 |
| 如何将描述符里的数据显示为图片? | noisy_dummy | Symbian | 2 | 2006-03-20 08:41 |
