×
Namespaces

Variants
Actions

Archived:Resize png/jpg image in Symbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code ExampleCompatibilityArticle
Created: savaj (31 Mar 2009)
Last edited: hamishwillee (19 Jun 2012)

When we load image using CImageDecoder, it might happen that size of image is either larger or smaller than screen size. In these scenario we, need resize loaded image. Symbian has CBitmapScaler class to resize/scale image. The following class illustrate how to resize image.

Note: This code will work on 2nd, 3rd and 5th edition. But the code example given below (link at bottom) is tested on 3rd edition device(N73) only.


Header required:

#include <FBS.H>
#include <BitmapTransforms.h>

Library needed:

LIBRARY fbscli.lib 
LIBRARY bitmaptransforms.lib

ImageResizer.h

#ifndef IMAGERESIZER_H
#define IMAGERESIZER_H
 
#include <e32base.h>
#include <FBS.H>
#include <BitmapTransforms.h>
 
 
class CFbsBitmap;
 
class MImageResizerObserver
{
public:
virtual void ResizeComplete(const TInt& aError) = 0;
};
 
class CImageResizer : public CActive
{
 
public:
 
~CImageResizer();
 
CFbsBitmap* Bitmap();
 
protected:
 
void RunL();
 
void DoCancel();
 
public:
 
CImageResizer(MImageResizerObserver* aObserver);
 
void ConstructL(CFbsBitmap& aBmp, const TSize& aSize);
 
private:
MImageResizerObserver* iObserver;
CFbsBitmap* iBitmap;
CBitmapScaler* iBitmapScaler;
};
 
#endif

ImageResizer.cpp

#include <eikenv.h>
#include "ImageResizer.h"
 
 
CImageResizer::CImageResizer(MImageResizerObserver* aObserver):CActive(EPriorityStandard)
{
iObserver = aObserver;
}
 
CImageResizer::~CImageResizer()
{
Cancel();
 
if(iBitmapScaler)
{
iBitmapScaler->Cancel();
delete iBitmapScaler;
iBitmapScaler = NULL;
}
}
 
void CImageResizer::ConstructL(CFbsBitmap& aBmp, const TSize& aSize)
{
CActiveScheduler::Add(this);
 
iBitmapScaler = CBitmapScaler::NewL();
 
iBitmap = &aBmp;
 
iBitmapScaler->Scale(&iStatus, *iBitmap, aSize);
SetActive();
 
}
 
void CImageResizer::RunL()
{
if(iStatus==KErrNone)
{
iObserver->ResizeComplete(iStatus.Int());
}
}
 
void CImageResizer::DoCancel()
{
iBitmapScaler->Cancel();
}
 
CFbsBitmap* CImageResizer::Bitmap()
{
return iBitmap;
}
 
//End of File


How to use this class??

//since this class is active object, we have to implement its observer
// create instance of a class in ConstructL() of your appui.
 
iImageResizer = new (ELeave) CImageResizer(this);
 
//then call ConstructL() method with passing reference of image and new size of image.
//iBitmap is of type CFbsBitmap
 
iImageResizer->ConstructL(*iBitmap,TSize(50,70));
 
//when CImageResizer completes resizing, it gives call back in
//ResizeComplete() method. now call Bitmap() method of CImageResizer to get image.
 
CFbsBitmap* pImage = iImageResizer->Bitmap();
//now use this pImage.

Code Example


Related links:

This page was last modified on 19 June 2012, at 07:59.
44 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.

×