Graphics.DrawImage(Image*, const RectF, REAL, REAL, REAL, REAL, Unit, ImageAttributes*, DrawImageAbort, VOID*) method
Applies to: desktop apps only
The Graphics::DrawImage method draws an image.
Syntax
Status DrawImage(
[in] Image *image,
[in, ref] const RectF &destRect,
[in] REAL srcx,
[in] REAL srcy,
[in] REAL srcwidth,
[in] REAL srcheight,
[in] Unit srcUnit,
[in] ImageAttributes *imageAttributes,
[in] DrawImageAbort callback,
[in] VOID *callbackData
);
Parameters
image [in]
Type: Image*Pointer to an Image object that specifies the source image.
destRect [in, ref]
Type: const RectFReference to a rectangle that bounds the drawing area for the image.
srcx [in]
Type: REALReal number that specifies the x-coordinate of the upper-left corner of the portion of the source image to be drawn.
srcy [in]
Type: REALReal number that specifies the y-coordinate of the upper-left corner of the portion of the source image to be drawn.
srcwidth [in]
Type: REALReal number that specifies the width of the portion of the source image to be drawn.
srcheight [in]
Type: REALReal number that specifies the height of the portion of the source image to be drawn.
srcUnit [in]
Type: UnitElement of the Unit enumeration that specifies the unit of measure for the image. The default value is UnitPixel.
imageAttributes [in]
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.
callback [in]
Type: DrawImageAbortCallback method used to cancel the drawing in progress. The default value is NULL.
callbackData [in]
Type: VOID*Pointer to additional data used by the method specified by the callback parameter. The default value is NULL.
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.
Remarks
The portion of the source image to be drawn is scaled to fit the rectangle.
Examples
The following example draws the original source image and then draws a portion of the image in a specified rectangle.
VOID Example_DrawImage6(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 a RectF object that specifies the destination of the image.
RectF destRect(200.0f, 10.0f, <REAL>image.GetWidth(), <REAL>image.GetHeight());
// 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 resized image.
graphics.DrawImage(
&image,
destRect,
srcX,
srcY,
srcWidth,
srcHeight,
UnitPixel,
&remapAttributes,
NULL,
NULL);
}
The following illustration shows the output of the preceding code.
.png)
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
Loading and Displaying Bitmaps
Drawing, Positioning, and Cloning Images
Send comments about this topic to Microsoft
Build date: 3/6/2012