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.

Scaling an image with RGA

From 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}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Tested with
Devices(s): Nokia N93, Nokia N95
Platform(s): S60 3rd Edition
Created: stolik (22 Sep 2008)
Last edited: lpvalente (18 Sep 2012)



This code snippet shows how to scale images. The resulting bitmap is created inside the function shown in this code snippet and passed back to caller, which should handle the destruction.

Note: In order to use this code, you need to install the Open C plug-in.


This example relies on the RGA API ngi framework.

To run this snippet you need to create a project according to Using RGA with Carbide.c++, and create a simple application like the Simple RGA application. You can also modify existing examples provided with Open C/C++ Plug-ins for S60 3rd Edition.

MMP file

The following capabilities and libraries are required:

LIBRARY euser.lib
LIBRARY runtime.lib
LIBRARY libc.lib
LIBRARY libm.lib
LIBRARY libpthread.lib

Note: The snippet itself does not require any special capabilities, but due to the use of the RGA API ngi framework, the resulting application requires SwEvent capability. (See also Open C/C++ DLL.)

Header file

using namespace ngi;
// ...
* ScalingImage
* helper function to make scaling of bitmap to support scalability
* bitmap is created into the same format as current back buffer
* @param aOrigBitmap bitmap object to scale from
* @param aSize size of created bitmap in pixels
* @param aScaledBitmap bitmap object to put result of scaling in
* @return OK, or error code

uint32 ScalingImage(IBitmap* aOrigBitmap,
const CSize& aSize,
IBitmap*& aScaledBitmap);
// ...

Source file

#include <errorcodes.h>         // ngi
#include <graphics.h> // ngi
#include <graphicscontext.h> // ngi
#include <ngibitmap.h> // ngi
#include <runtime.h> // ngi
#include <standardtypes.h> // ngi
// ---------------------------------------------------------
// Scaling image
// ---------------------------------------------------------
uint32 CExampleApplication::ScalingImage(IBitmap* aOrigBitmap,
const CSize& aSize,
IBitmap*& aScaledBitmap)
// preparing for scaling image
ReturnCode ret = CRuntime::CreateInstance(aScaledBitmap);
if (ret != OK)
return ret;
uint32 colorFormat =
mBackBuffer->GetColorFormat(); // GRAPHICS_FORMAT_RGB888
ret = aScaledBitmap->Reconfigure(CSize(aSize.mX, aSize.mY), colorFormat);
if (ret != OK)
return ret;
IGraphicsContext* iContext;
ret = CRuntime::CreateInstance( iContext );
if (ret != OK)
return ret;
// scale original Bitmap to new size
//TODO: error handling of ret value
ret = aScaledBitmap->Lock();
ret = aOrigBitmap->Lock();
const uint32 KTransparentColor = 0;
ret = iContext->Scale(CRect(0, 0, aSize.mX, aSize.mY), *aOrigBitmap);
ret = aOrigBitmap->Unlock();
ret = aScaledBitmap->Unlock();
iContext= NULL;
return ret;


This function will initialise a new bitmap and scale it to the specified size. Releasing aScaledBitmap should be done by the caller.

This page was last modified on 18 September 2012, at 18:08.
20 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.