Graphics.DrawImage(Image*, REAL, REAL, REAL, REAL, REAL, REAL, Unit) method

Applies to: desktop apps only

The Graphics::DrawImage method draws an image.

Syntax

Status DrawImage(
  [in]  Image *image,
  [in]  REAL x,
  [in]  REAL y,
  [in]  REAL srcx,
  [in]  REAL srcy,
  [in]  REAL srcwidth,
  [in]  REAL srcheight,
  [in]  Unit srcUnit
);

Parameters

image [in]

Type: Image*

Pointer to an Image object that specifies the source image.

x [in]

Type: REAL

Real number that specifies the x-coordinate of the upper-left corner of the destination position at which to draw the image.

y [in]

Type: REAL

Real number that specifies the y-coordinate of the upper-left corner of the destination position at which to draw the image.

srcx [in]

Type: REAL

Real number that specifies the x-coordinate of the upper-left corner of the portion of the source image to be drawn.

srcy [in]

Type: REAL

Real number that specifies the y-coordinate of the upper-left corner of the portion of the source image to be drawn.

srcwidth [in]

Type: REAL

Real number that specifies the width of the portion of the source image to be drawn.

srcheight [in]

Type: REAL

Real number that specifies the height of the portion of the source image to be drawn.

srcUnit [in]

Type: Unit

Element of the Unit enumeration that specifies the unit of measure for the image. The default value is UnitPixel.

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.

Examples

The following example draws a portion of an image. The portion of the source image to be drawn is scaled to fit the rectangle.


VOID Example_DrawImage15(HDC hdc)

{
   Graphics graphics(hdc);

   // Create an Image object.
   Image image(L"climber.jpg");

   // Draw the original source image.
   graphics.DrawImage(&image, 10, 10);

   // Set up the location for the image and the portion of the source to draw.
   REAL x = 200.0f;
   REAL y = 30.0f;
   REAL srcx = 70.0f;
   REAL srcy = 20.0f;
   REAL srcwidth = 100.0f;
   REAL srcheight = 200.0f;
   Unit srcunit = UnitPixel;

   // Draw the image.
   graphics.DrawImage(&image, x, y, srcx, srcy, srcwidth, srcheight, srcunit);
}

The following illustration shows the output of the preceding code.

Illustration showing two versions of one image; the second is a subset of the first

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Graphics
Image
Loading and Displaying Bitmaps
Drawing, Positioning, and Cloning Images

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show: