Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 08:02, 24 July 2008.

Bitmap class for direct screen access

From Forum Nokia Wiki

If direct screen access is used for rendering in e.g. a game, it is desirable to store images (sprites) in a way it can be quickly rendered to the screen buffer.

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

Links

Code

////////////////////////////////
// header
////////////////////////////////
 
#define TPixel TUint32
 
class CMyBitmap : public CBase
	{
	...
	
	TPixel* iData;
        TSize iSize;
	
	...
    };
 
////////////////////////////////
// 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\\") );
#else
    path.Copy(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName().Left(2));
    TFileName relPath;
    CEikonEnv::Static()->FsSession().PrivatePath( relPath );
    path.Append( relPath);
#endif
    
    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();
    		sourceUtil.IncXPos();
    		}
    	sourceUtil.End();
    	}
    CleanupStack::PopAndDestroy();
    }
 
...
 
Related Discussions
Thread Thread Starter Forum Replies Last Post
Realtime graphics on 7650 suckho General Symbian C++ 2 2002-09-18 11:14
Creating image file from bitmap. mahavirjain General Symbian C++ 3 2006-06-13 06:48
How can I draw PNGs? putek20 General Symbian C++ 2 2003-11-08 09:54
Displaying of Raw Bitmap data in the Display gilly_kumar General Symbian C++ 2 2005-10-10 18:42
How to make an internet connection using Series60 MIDP SDK for Symbian_OS v1.2 emulor jrmfelipe Mobile Java Networking & Messaging & Security 12 2004-05-07 09:32
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZgamesQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX