The following example draws a portion of an image. The portion of the source image to be drawn is scaled to fit the rectangle.
C++
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);
}
PowerBASIC
SUB GDIP_GdipDrawImagePointRect (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pImage AS DWORD
LOCAL strFileName AS STRING
LOCAL x AS SINGLE
LOCAL y AS SINGLE
LOCAL srcx AS SINGLE
LOCAL srcy AS SINGLE
LOCAL srcwidth AS SINGLE
LOCAL srcheight AS SINGLE
LOCAL srcUnit AS LONG
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create the Image object
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
' // Draw the original source image.
hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)
' // Set up the location for the image and the portion of the source to draw.
x = 200.0!
y = 30.0!
srcx = 70.0!
srcy = 20.0!
srcwidth = 100.01
srcheight = 200.0!
srcunit = %UnitPixel
' // Draw the image
hStatus = GdipDrawImagePointRect(pGraphics, pImage, x, y, srcx, srcy, srcwidth, srcheight, srcunit)
' // Cleanup
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipDrawImagePointRect.png)