• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipGetTextureImage

Started by José Roca, June 28, 2008, 08:06:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



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.