Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 13:54, 14 October 2008.

CS001109 - Scaling an image with RGA

From Forum Nokia Wiki



ID CS001109 Creation date October 1, 2008
Platform S60 3rd Edition Tested on devices Nokia N93, Nokia N95
Category Open C/C++ Subcategory RGA


Keywords (APIs, classes, methods, functions):

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.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Need help with scaling gigglie General Symbian C++ 7 2008-03-10 10:31
Image not showing up on target device, Nokia 7610 shufeilei Mobile Java General 4 2006-07-07 23:43
creating dynamic custom image farhanx Mobile Java General 1 2006-11-05 15:55
AknIconUtils is caching the image Tatanka.nbr1 General Symbian C++ 12 2007-01-05 20:08
Image Menu with canvas efeba Mobile Java Media (Graphics & Sounds) 2 2003-06-26 12:33
 
Powered by MediaWiki
RDF Facets: qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX