|
||
The example code contained in this document demonstrates:
blitting a bitmap to the screen
blitting a rectangular piece of a bitmap to the screen
blitting a bitmap under a mask
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);
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);
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();
unlike with an ordinary BitBlit()
, with
BitBltMasked()
you always have to specify what part of the bitmap
to display: here we just set bmpPieceRect
so that the whole bitmap
is displayed
if the mask bitmap is smaller than the source bitmap, then it is tiled across the bitmap
for an inverted mask, set the last argument to
BitBltMasked()
to ETrue