Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



How to draw reduced and enlarged bitmaps

The bitmap blitting functions of the bitmapped graphics context (CBitmapContext) cannot be used to perform scaling of the bitmap, but always draws the bitmap using its dimensions in pixels. The overloaded GDI CGraphicsContext::DrawBitmap() function, however, can be used to draw a bitmap:

Note that DrawBitmap() is slower than BitBlt(), so BitBlt() should be used in preference wherever possible.


Draw a bitmap at a set size in twips

A bitmap can have a real world size in twips set for it, and be drawn scaled that size.

  1. Construct a TSize with the required dimensions in twips.

  2. Set the size of the bitmap using CFbsBitmap::SetSizeInTwips(). The default size in twips of a bitmap when loaded is (0,0).

  3. Draw the bitmap using DrawBitmap()

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

// Set twips size
TSize bmpSizeInTwips(2000,2000);
bitmap->SetSizeInTwips(bmpSizeInTwips);
gc.DrawBitmap(TPoint(50,50), bitmap);

[Top]


Draw a bitmap in a given rectangle

DrawBitmap() can also draw a bitmap by stretching it to fit a given rectangle.

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

// Draw bitmap stretched from the origin to 100,100
TRect rect(0,0,100,100);
gc.DrawBitmap(rect, bitmap);