The following example creates a texture brush and sets the transformation of the brush. The code then gets the brush's transformation matrix and proceeds to inspect or use the elements.
C++
VOID Example_GetTransform(HDC hdc)
{
Graphics graphics(hdc);
// Create a texture brush, and set its transform.
Image image(L"marble.jpg");
TextureBrush textureBrush(&image);
textureBrush.ScaleTransform(3, 2);
// Obtain information about the texture brush.
Matrix matrix;
REAL elements[6];
textureBrush.GetTransform(&matrix);
matrix.GetElements(elements);
for(INT j = 0; j <=5; ++j)
{
// Inspect or use the value in elements[j].
}
}
PowerBASIC
SUB GDIP_GetTextureTransform (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)
' // Create a texture brush, and set its transform.
strFileName = UCODE$("houseandtree.gif")
hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
hStatus = GdipCreateTexture(pImage, %WrapModeTile, pTextureBrush)
hStatus = GdipScaleTextureTransform(pTextureBrush, 3, 2, %MatrixOrderPrepend)
' // Obtain information about the texture brush.
hStatus = GdipCreateMatrix(pMatrix)
DIM elements(23) AS SINGLE ' 6 * SIZEOF(SINGLE), i.e. 24 elements
hStatus = GdipGetTextureTransform(pTextureBrush, pMatrix)
hStatus = GdipGetMatrixElements(pMatrix, elements(0))
LOCAL j AS LONG
FOR j = 0 TO 23
' // Inspect or use the value in elements[j].
OutputDebugString STR$(elements(j))
NEXT
' // Cleanup
IF pMatrix THEN GdipDeleteMatrix(pMatrix)
IF pImage THEN GdipDisposeImage(pImage)
IF pTextureBrush THEN GdipDeleteBrush(pTextureBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB