Bitmap.Clone(const Rect, PixelFormat) method

Applies to: desktop apps only

The Bitmap::Clone method creates a new Bitmap object by copying a portion of this bitmap.

Syntax

Bitmap* Clone(
  [in, ref]  const Rect &rect,
  [in]       PixelFormat format
);

Parameters

  • rect [in, ref]
    Type: const Rect

    Reference to a rectangle that specifies the portion of this bitmap to be copied.

  • format [in]
    Type: PixelFormat

    Integer that specifies the pixel format of the new bitmap. The PixelFormat data type and constants that represent various pixel formats are defined in Gdipluspixelformats.h. For more information about pixel format constants, see Image Pixel Format Constants.

Return value

Type:

Type: Bitmap*****

This method returns a pointer to the new Bitmap object.

Examples

The following example creates a Bitmap object from an image file, clones the upper-left portion of the image, and then draws the cloned image.

VOID Example_Clone(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Bitmap object from a JPEG file.
   Bitmap bitmap(L"Climber.jpg");

   // Clone a portion of the bitmap.
   Bitmap* clone = bitmap.Clone(Rect(0, 0, 100, 100), PixelFormatDontCare);

   // Draw the clone.
   graphics.DrawImage(clone, 0, 0);
   
   delete clone;
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusheaders.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Bitmap

Bitmap Constructors

Clone

Image

Image Pixel Format Constants

Rect

Using Images, Bitmaps, and Metafiles

Images, Bitmaps, and Metafiles

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012