The following example creates a texture brush and sets the transformation of the brush. The code then uses the transformed brush to fill a rectangle.
C++
VOID Example_MultiplyTransform(HDC hdc)
{
Graphics graphics(hdc);
Matrix matrix(3, 0, 0, 1, 0, 0); // Horizontal stretch
Image image(L"HouseAndTree.Gif");
TextureBrush textureBrush(&image);
textureBrush.RotateTransform(30); // rotate
textureBrush.MultiplyTransform(&matrix, MatrixOrderAppend); // stretch
graphics.FillRectangle(&textureBrush, 0, 0, 400, 200);
}
PowerBASIC
SUB GDIP_MultiplyTextureTransform (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pImage AS DWORD
LOCAL pTextureBrush AS DWORD
LOCAL pMatrix AS DWORD
LOCAL strFileName AS STRING
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateMatrix2(3, 0, 0, 1, 0, 0, pMatrix) ' // Horizontal stretch
' // Create a texture brush, and set its wrap mode.
strFileName = UCODE$("HouseAndTree.gif")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
hStatus = GdipCreateTexture(pImage, %WrapModeTile, pTextureBrush)
hStatus = GdipRotateTextureTransform(pTextureBrush, 30, %MatrixOrderPrepend) ' rotate
hStatus = GdipMultiplyTextureTransform(pTextureBrush, pMatrix, %MatrixOrderAppend) ' stretch
hStatus = GdipFillRectangleI(pGraphics, pTextureBrush, 0, 0, 400, 200)
' // Cleanup
IF pMatrix THEN GdipDeleteMatrix(pMatrix)
IF pImage THEN GdipDisposeImage(pImage)
IF pTextureBrush THEN GdipDeleteBrush(pTextureBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipMultiplyTextureTransform.png)