Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to draw bitmaps

The example code contained in this document demonstrates:


Bitmap block transfer

Use CBitmapContext::BitBlt() to blit a CFbsBitmap to the screen.

The example assumes bitmap is a pointer to a valid CFbsBitmap.

// draw the bitmap using bitmap block transfer
TPoint pos(50,50);
gc.BitBlt(pos, bitmap);

[Top]


Block transfer of a rectangular piece of a bitmap

You can blit a rectangular piece of a bitmap to the screen.

The example assumes bitmap is a pointer to a valid CFbsBitmap.

...
// set a rectangle for the top-left quadrant of the source bitmap
TSize bmpSizeInPixels=bitmap->SizeInPixels();
TSizebmpPieceSize(bmpSizeInPixels.iWidth/2,bmpSizeInPixels.iHeight/2);
TRect bmpPieceRect(TPoint(0,0),bmpPieceSize);

// blit only the piece of the bitmap indicated by bmpPieceRect
TPoint pos(100,100);
gc.BitBlt(pos, bitmap, bmpPieceRect);

[Top]


Masked bitmap block transfer

Masks can be used to select which parts of a bitmap are drawn by CBitmapContext::BitBltMasked().

Masks can be used to not display pixels of the source bitmap if their corresponding mask pixel is black, or, alternatively, where the mask is white (called an inverted mask).

The following figure shows successively a source bitmap, a mask, and the outcome when they are blitted with BitBltMasked().

The example assume bitmap is a pointer to a valid CFbsBitmap.

// Load the mask bitmap, just like any other
CFbsBitmap* maskBitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(maskBitmap);
User::LeaveIfError(maskBitmap->
  Load(multiBitmapFile,EMbmGrbmap2Smilmask));

// Calculate rectangle for the whole bitmap
TRect bmpPieceRect(TPoint(0,0),bitmap->SizeInPixels());

// Blit using a masking bitmap, with no inversion
gc.BitBltMasked(TPoint(50,50),bitmap,bmpPieceRect,maskBitmap,EFalse);

...
// clean up
CleanupStack::PopAndDestroy();


Notes