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 06:40, 27 November 2007.

How to draw transparent image without mask

From Forum Nokia Wiki


We often use key color ( RGB(255,0,255) ) to transparent image in game development. But BitBlt function not supports this feature in Symbian OS, so you must do it yourself. Look at these snippets of code:

Note! This example does not lock the heap while drawing so on devices using S60 2nd Edition it will randomly crash. On devices using S60 3rd Edition it most probably won't even run.

To fix this you must use the bitmap's LockHeap() method before using the DataAddress() method and UnlockHeap() after everything is done.

Example

void DrawBitmap( const TPoint& ptPoint, const CFbsBitmap* pBitmap, 
		const TRect& rcRect, const TInt nKeyColor )
{
	if( pBitmap == NULL ||
		rcRect.iTl.iX > pBitmap->SizeInPixels().iWidth ||
		rcRect.iTl.iY > pBitmap->SizeInPixels().iHeight ||
		ptPoint.iX > m_pOffScreenBmp->SizeInPixels().iWidth ||
		ptPoint.iY > m_pOffScreenBmp->SizeInPixels().iHeight ||
		ptPoint.iX + rcRect.Width() < 0 ||
		ptPoint.iY + rcRect.Height() < 0 )
	{
		return ;
	}
 
	TPoint iPoint( ptPoint );
	TRect iRect( rcRect );
 
	if( iRect.iTl.iX < 0 )
	{
		iRect.iTl.iX = 0;
	}
	if( iRect.iTl.iY < 0 )
	{
		iRect.iTl.iY = 0;
	}
	if( iPoint.iX < 0 )
	{
		iRect.iTl.iX -= iPoint.iX;
		iPoint.iX = 0;
	}
	if( iPoint.iY < 0 )
	{
		iRect.iTl.iY -= iPoint.iY;
		iPoint.iY = 0;
	}
	TSize sBack = m_pOffScreenBmp->SizeInPixels();
	TSize sFront = pBitmap->SizeInPixels();
	if( iRect.iBr.iX > sFront.iWidth )
	{
		iRect.iBr.iX = sFront.iWidth;
	}
	if( iRect.iBr.iY > sFront.iHeight )
	{
		iRect.iBr.iY = sFront.iHeight;
	}
	if( iPoint.iX + iRect.Width() > sBack.iWidth )
	{
		iRect.iBr.iX = sBack.iWidth + iRect.iTl.iX - iPoint.iX;
	}
	if( iPoint.iY + iRect.Height() > sBack.iHeight )
	{
		iRect.iBr.iY = sBack.iHeight + iRect.iTl.iY - iPoint.iY;
	}
 
	TUint16* pBack = ( TUint16* ) m_pOffScreenBmp->DataAddress();
	TUint16* pFront = ( TUint16* ) pBitmap->DataAddress();
	pBack += iPoint.iY * 
		( m_pOffScreenBmp->ScanLineLength( sBack.iWidth, EColor4K ) >> 1 )
		 + iPoint.iX;
	pFront += iRect.iTl.iY * 
		( pBitmap->ScanLineLength( sFront.iWidth, EColor4K ) >> 1 )
		 + iRect.iTl.iX;
 
	TInt iRectWidth = iRect.Width();
	TInt iRectHeight = iRect.Height();
	TInt iStepBack = ( m_pOffScreenBmp->ScanLineLength( sBack.iWidth, EColor4K ) >> 1 )
		 - iRectWidth;
	TInt iStepFront = ( pBitmap->ScanLineLength( sFront.iWidth, EColor4K ) >> 1 )
		 - iRectWidth;
 
	iStepBack += iRectWidth;
	iStepFront += iRectWidth;
 
	for( TInt i = 0; i < iRectHeight; 
		pBack += iStepBack, pFront += iStepFront, i++ )
		for( TInt j = 0; j < iRectWidth; j++ )
			if( ( pFront[j] ) != nKeyColor )
				pBack[j] = pFront[j];
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
CEikLabel with overrided color and backgroud skin eekisa Symbian User Interface 5 2005-04-06 15:51
SetBackgroundColor() in SDK 6.1 Nokia_Archive Symbian Tools & SDKs 1 2002-05-29 19:30
Icons , Jpg and DobuleLargeListBox XciteZ General Symbian C++ 1 2005-08-03 11:36
using transparent bitmap with non-gui idris_stone Symbian User Interface 3 2008-03-03 09:52
Drawing Lines on an Image (image graphics object returns null) nicenouman Mobile Java General 4 2006-09-21 10:15
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZgamesQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX