Graphics::DrawCachedBitmap method

The Graphics::DrawCachedBitmap method draws the image stored in a CachedBitmap object.


Status DrawCachedBitmap(
  IN CachedBitmap *cb,
  IN INT          x,
  IN INT          y



Type: CachedBitmap*

Pointer to a CachedBitmap object that contains the image to be drawn.


Type: INT

Integer that specifies the x-coordinate of the upper-left corner of the image.


Type: INT

Integer that specifies the y-coordinate of the upper-left corner of the image.

Return Value

Type: Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.


A CachedBitmap object stores an image in a format that is optimized for a particular display screen. You cannot draw a cached bitmap to a printer or to a metafile.

Cached bitmaps will not work with any transformations other than translation.

When you construct a CachedBitmap object, you must pass the address of a Graphicsobject to the constructor. If the screen associated with that Graphicsobject has its bit depth changed after the cached bitmap is constructed, then the Graphics::DrawCachedBitmap method will fail, and you should reconstruct the cached bitmap. Alternatively, you can hook the display change notification message and reconstruct the cached bitmap at that time.


The following example calls Graphics::DrawCachedBitmap to draw the image stored in a CachedBitmap object.

VOID Example_DrawCachedBitmap(HDC hdc)
   Graphics graphics(hdc);

   // Create Bitmap object.
   Bitmap bitmap(L"Climber.jpg");

   // Use the Bitmap object to create a CachedBitmap object.
   CachedBitmap cachedBitmap(&bitmap, &graphics);

   // Draw the cached bitmap.
   graphics.DrawCachedBitmap(&cachedBitmap, 20, 10);


Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusgraphics.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See Also


Drawing, Positioning, and Cloning Images


Using a Cached Bitmap to Improve Performance