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 28, 2008, 08:06:50 PM

Title: GDI+: GdipGetTextureImage
Post by: José Roca on June 28, 2008, 08:06:50 PM


The following example creates a texture brush and uses it to fill an ellipse. The code then gets the brush's image and draws it.

C++


VOID Example_GetImage(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a texture brush, and use it to fill an ellipse.
   Image image(L"sample.jpg");
   TextureBrush textureBrush(&image);
   graphics.FillEllipse(&textureBrush, 0, 0, 200, 100);

   // Get the brush's image, and draw that image.
   Image* pImage = textureBrush.GetImage();
   graphics.DrawImage(pImage, 10, 150);
}


PowerBASIC


SUB GDIP_GetTextureImage (BYVAL hdc AS DWORD)

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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a texture brush, and use it to fill an ellipse.
   strFileName = UCODE$("MyTexture.png")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
   hStatus = GdipCreateTexture(pImage, %WrapModeTile, pTextureBrush)
   hStatus = GdipFillEllipseI(pGraphics, pTextureBrush, 0, 0, 200, 100)

   ' // Get the brush's image, and draw that image.
   hStatus = GdipGetTextureImage(pTextureBrush, pImage2)
   hStatus = GdipDrawImageI(pGraphics, pImage2, 10, 150)

   ' // Cleanup
   IF pImage THEN GdipDisposeImage(pImage)
   IF pImage2 THEN GdipDisposeImage(pImage2)
   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/GdipGetTextureImage.png)