Graphics.DrawCachedBitmap method

Applies to: desktop apps only

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


Status DrawCachedBitmap(
  [in]  CachedBitmap *cb,
  [in]  INT x,
  [in]  INT y


cb [in]

Type: CachedBitmap*

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

x [in]

Type: INT

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

y [in]

Type: INT

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

Return value


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 Graphics object to the constructor. If the screen associated with that Graphics object 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

Minimum supported server

Windows 2000 Server


GDI+ 1.0


Gdiplusgraphics.h (include Gdiplus.h)





See also

Using a Cached Bitmap to Improve Performance
Drawing, Positioning, and Cloning Images



Send comments about this topic to Microsoft

Build date: 3/6/2012