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. Thanks for all your past and future contributions.

Bitmap class for direct screen access

From Wiki
Jump to: navigation, search

This article shows a bitmap class that can be used to store images for quick rendering to the screen buffer when using direct screen access. This might be used, for example, in rendering sprites in a DSA enabled game

Article Metadata
Created: gafgafgaf (07 May 2007)
Last edited: hamishwillee (14 Jun 2013)


Remarks for the sample

  • It assumes, that images are stored in an mbm file in the application's private directory
  • It reserves space on the heap to store the image and converts the bitmap in a way it can be directly rendered in the screen buffer
  • Remember to use /c24 switch when creating mbm file with mifconv tool to ensure right color depth



Header file (.h)

#define TPixel TUint32
class CMyBitmap : public CBase
TPixel* iData;
TSize iSize;

Source file (cpp)

_LIT( KMyBitmapFile,"MyGame.mbm" );
// CMyBitmap class represents a bitmap ready for rendering
// with direct screen access
// aIndex is the image's index in the mbm file
void CMyBitmap::ConstructL( TInt aIndex )
CFbsBitmap* image = new( ELeave ) CFbsBitmap;
CleanupStack::PushL( image );
// Finding out the location of the mbm file
TFileName path;
#ifdef __WINS__
path.Append( _L("z:\\resource\\apps\\") );
TFileName relPath;
CEikonEnv::Static()->FsSession().PrivatePath( relPath );
path.Append( relPath);
path.Append( KMyBitmapFile );
// Load bitmap
User::LeaveIfError( image->Load( path, aIndex, EFalse ) );
// Creating space on heap
iSize = image->SizeInPixels();
// Remember to delete it in the destructor
iData = new ( ELeave ) TPixel[ iSize.iWidth * iSize.iHeight ];
// TBitmapUtil helps accessing pixels safely
TBitmapUtil sourceUtil( image );
for ( TInt y = 0; y < iSize.iHeight; y++ )
sourceUtil.Begin( TPoint( 0, y ) );
for ( TInt x = 0; x < iSize.iWidth; x++ )
*(iData + y * iSize.iWidth + x) = sourceUtil.GetPixel();
This page was last modified on 14 June 2013, at 05:05.
50 page views in the last 30 days.