Graphics::DrawImage(Image*,constPointF*,INT,REAL,REAL,REAL,REAL,Unit,constImageAttributes*,DrawImageAbort,VOID*) method (gdiplusgraphics.h)

The Graphics::DrawImage method draws an image.

Syntax

Status DrawImage(
  [in] Image                 *image,
  [in] const PointF          *destPoints,
  [in] INT                   count,
  [in] REAL                  srcx,
  [in] REAL                  srcy,
  [in] REAL                  srcwidth,
  [in] REAL                  srcheight,
  [in] Unit                  srcUnit,
  [in] const ImageAttributes *imageAttributes,
  [in] DrawImageAbort        callback,
  [in] VOID                  *callbackData
);

Parameters

[in] image

Type: Image*

Pointer to an Image object that specifies the source image.

[in] destPoints

Type: const PointF*

Pointer to an array of PointF objects that specify the area, in a parallelogram, in which to draw the image.

[in] count

Type: INT

Integer that specifies the number of elements in the destPoints array.

[in] srcx

Type: REAL

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

[in] srcy

Type: REAL

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

[in] srcwidth

Type: REAL

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

[in] srcheight

Type: REAL

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

[in] srcUnit

Type: Unit

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

[in] imageAttributes

Type: ImageAttributes*

Pointer to an ImageAttributes object that specifies the color and size attributes of the image to be drawn. The default value is NULL.

[in] callback

Type: DrawImageAbort

Callback method used to cancel the drawing in progress. The default value is NULL.

[in] callbackData

Type: VOID*

Pointer to additional data used by the method specified by the callback parameter. The default value is NULL.

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.

Remarks

The value of the count parameter must equal 3 to specify the coordinates of the upper-left corner, upper-right corner, and lower-left corner of the parallelogram. The coordinate of the lower-right corner is calculated using the three given coordinates, the width, and the height of the image. The portion of the source image to be drawn is scaled to fit the parallelogram.

Examples

The following example draws the original source image and then draws a portion of the image in a specified parallelogram.

VOID Example_DrawImage4(HDC hdc)

{

   Graphics graphics(hdc);

   // Create an Image object.
   Image image(L"pattern.png");

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

   // Define the portion of the image to draw.
   REAL srcX = 70.0f;
   REAL srcY = 20.0f;
   REAL srcWidth = 100.0f;
   REAL srcHeight = 100.0f;

   // Create an array of Point objects that specify the destination of the cropped image.
   PointF destPoints[3] = {
   PointF(230.0f, 30.0f),
   PointF(350.0f, 50.0f),
   PointF(275.0f, 120.0f)};

   Point* pdestPoints = destPoints; 

   // Create an ImageAttributes object that specifies a recoloring from red to blue.
   ImageAttributes remapAttributes;
   ColorMap redToBlue;
   redToBlue.oldColor = Color(255, 255, 0, 0);
   redToBlue.newColor = Color(255, 0, 0, 255);
   remapAttributes.SetRemapTable(1, &redToBlue);

   // Draw the cropped image.
   graphics.DrawImage(
   &image,
   pdestPoints,
   3,
   srcX,
   srcY,
   srcWidth,
   srcHeight,
   UnitPixel,
   &remapAttributes,
   NULL,
   NULL);
}

The following illustration shows the output of the preceding code.

Illustration showing a multicolored checkerboard pattern, then an enlarged, two-toned subset of that pattern, sheared to a parallelogram

Requirements

Requirement Value
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

Graphics

Image

ImageAttributes

Loading and Displaying Bitmaps

Point

SetRemapTable

Unit