The following example calls
GdipDrawImageRectRectI twice. In both calls, the specified source rectangle is four times as large as the image itself. In the first call to
GdipDrawImageRectRectI, the
ImageAttributes object has its wrap mode set to
WrapModeClamp, so the portion of the source rectangle outside the image is filled with red according to the second argument passed to
SetWrapMode. In the second call to
GdipDrawImageRectRectI, the
ImageAttributes object has its wrap mode set to
WrapModeTile, so the portion of the source rectangle outside the image is filled with repeated copies of the image.
C++
VOID Example_SetWrapMode(HDC hdc)
{
Graphics graphics(hdc);
Image image(L"Climber.jpg");
ImageAttributes imAtt;
imAtt.SetWrapMode(WrapModeClamp);
graphics.DrawImage(&image,
Rect(10, 10, image.GetWidth(), image.GetHeight()), // dest rect
0, 0, 2*image.GetWidth(), 2*image.GetHeight(), // source rect
UnitPixel,
&imAtt);
imAtt.SetWrapMode(WrapModeTile);
graphics.DrawImage(&image,
Rect(200, 10, image.GetWidth(), image.GetHeight()), // dest rect
0, 0, 2*image.GetWidth(), 2*image.GetHeight(), // source rect
UnitPixel,
&imAtt);
}
PowerBASIC
SUB GDIP_SetImageAttributesWrapMode (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pImage AS DWORD
LOCAL pImgAttr AS DWORD
LOCAL strFileName AS STRING
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
hStatus = GdipCreateFromHDC(hdc, pGraphics)
strFileName = UCODE$("climber.jpg")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
hStatus = GdipCreateImageAttributes(pImgAttr)
GdipSetImageAttributesWrapMode(pImgAttr, %WrapModeClamp, GDIP_ARGB(255, 255, 0, 0), %FALSE)
hStatus = GdipGetImageWidth(pImage, nWidth)
hStatus = GdipGetImageHeight(pImage, nHeight)
hStatus = GdipDrawImageRectRectI(pGraphics, pImage, _
10, 10, nWidth, nHeight, _ ' dest rect
0, 0, 2*nWidth, 2*nHeight, _ ' source dest
%UnitPixel, pImgAttr, %NULL, %NULL)
GdipSetImageAttributesWrapMode(pImgAttr, %WrapModeTile, GDIP_ARGB(255, 255, 0, 0), %FALSE)
hStatus = GdipDrawImageRectRectI(pGraphics, pImage, _
200, 10, nWidth, nHeight, _ ' dest rect
0, 0, 2*nWidth, 2*nHeight, _ ' source dest
%UnitPixel, pImgAttr, %NULL, %NULL)
' // Cleanup
IF pImgAttr THEN GdipDisposeImageAttributes(pImgAttr)
IF pImage THEN GdipDisposeImage(pImage)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipSetImageAttributesWrapMode.png)