Contents |
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.
#include <ImageConversion.h> //CImageDecoder
#include <Fbs.h> //CFbsBitmap
#include <BitmapTransforms.h> //CBitmapScaler
LIBRARY mgfetch.lib
LIBRARY bafl.lib
LIBRARY fbscli.lib
LIBRARY efsrv.lib
LIBRARY imageconversion.lib
LIBRARY bitmaptransforms.lib
capability ReadUserData // MgFetch::RunL()
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();
}
"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.
//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;
}
"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.
//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.
No related wiki articles found