×
Namespaces

Variants
Actions

Scaling an image with RGA

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

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


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

Contents

Overview

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.

Preconditions

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:

CAPABILITY SwEvent
STATICLIBRARY libcrt0.lib
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;
}
iContext->SetGraphicsDevice(*aScaledBitmap);
 
// scale original Bitmap to new size
//TODO: error handling of ret value
ret = aScaledBitmap->Lock();
ret = aOrigBitmap->Lock();
const uint32 KTransparentColor = 0;
iContext->Clear(KTransparentColor);
ret = iContext->Scale(CRect(0, 0, aSize.mX, aSize.mY), *aOrigBitmap);
ret = aOrigBitmap->Unlock();
ret = aScaledBitmap->Unlock();
 
iContext->Release();
iContext= NULL;
return ret;
}

Postconditions

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 21:08.
35 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.

×