Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 29, 2008, 01:06:03 PM

Title: GDI+: GdipResetTextureTransform
Post by: José Roca on June 29, 2008, 01:06:03 PM


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_ResetTransform(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a texture brush, and set its transformation.
   Image image(L"HouseAndTree.Gif");
   TextureBrush textureBrush(&image);
   textureBrush.RotateTransform(30);

   // Fill a rectangle with the transformed texture brush.
   graphics.FillRectangle(&textureBrush, 0, 0, 200, 100);

   textureBrush.ResetTransform();
   
   // Fill a rectangle with the texture brush (no transformation).
   graphics.FillRectangle(&textureBrush, 220, 0, 200, 100);
}


PowerBASIC


SUB GDIP_ResetTextureTransform (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pImage AS DWORD
   LOCAL pTextureBrush AS DWORD
   LOCAL strFileName AS STRING

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a texture brush, and set its transformation.
   strFileName = UCODE$("HouseAndTree.gif")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
   hStatus = GdipCreateTexture(pImage, %WrapModeTile, pTextureBrush)
   hStatus = GdipRotateTextureTransform(pTextureBrush, 30, %MatrixOrderPrepend)         ' rotate

   ' // Fill a rectangle with the transformed texture brush.
   hStatus = GdipFillRectangleI(pGraphics, pTextureBrush, 0, 0, 200, 100)

   hStatus = GdipResetTextureTransform(pTextureBrush)

   ' // Fill a rectangle with the texture brush (no transformation).
   hStatus = GdipFillRectangleI(pGraphics, pTextureBrush, 220, 0, 200, 100)

   ' // Cleanup
   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/GdipResetTextureTransform.png)