Graphics.DrawImage(Image*, INT, INT, INT, INT, INT, INT, Unit) method
Applies to: desktop apps only
The Graphics::DrawImage method draws an image.
Syntax
Status DrawImage(
[in] Image *image,
[in] INT x,
[in] INT y,
[in] INT srcx,
[in] INT srcy,
[in] INT srcwidth,
[in] INT srcheight,
[in] Unit srcUnit
);
Parameters
image [in]
Type: Image*Pointer to an Image object that specifies the source image.
x [in]
Type: INTInteger that specifies the x-coordinate of the upper-left corner of the destination position at which to draw the image.
y [in]
Type: INTInteger that specifies the y-coordinate of the upper-left corner of the destination position at which to draw the image.
srcx [in]
Type: INTInteger that specifies the x-coordinate of the upper-left corner of the portion of the source image to be drawn.
srcy [in]
Type: INTInteger that specifies the y-coordinate of the upper-left corner of the portion of the source image to be drawn.
srcwidth [in]
Type: INTInteger that specifies the width of the portion of the source image to be drawn.
srcheight [in]
Type: INTInteger 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.
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 a specified parallelogram.
VOID Example_DrawImage12(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.
int x = 200;
int y = 30;
int srcx = 70;
int srcy = 20;
int srcwidth = 100;
int srcheight = 200;
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.
.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