• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetTextureWrapMode

Started by José Roca, June 29, 2008, 11:55:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a texture brush, sets the wrap mode of the brush, and uses the brush to fill a rectangle. Next, the code gets the wrap mode of the brush and stores the value. The code creates a second texture brush and uses the stored wrap mode to set the wrap mode of the second texture brush. Then, the code uses the second texture brush to fill a rectangle.

C++


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

   // Create a texture brush, and set its wrap mode.
   Image image(L"HouseAndTree.gif");
   TextureBrush textureBrush(&image);
   textureBrush.SetWrapMode(WrapModeTileFlipX);
   graphics.FillRectangle(&textureBrush, 0, 0, 200, 200);

   // Get the brush's wrap mode.
   WrapMode wrapMode = textureBrush.GetWrapMode();
   
   // Create a second texture brush with the same wrap mode.
   Image image2(L"RainbowR.bmp");
   TextureBrush textureBrush2(&image2);
   textureBrush2.SetWrapMode(wrapMode);
   graphics.FillRectangle(&textureBrush2, 250, 0, 200, 200);
}


PowerBASIC


SUB GDIP_GetTextureWrapMode (BYVAL hdc AS DWORD)

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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a texture brush, and set its wrap mode.
   strFileName = UCODE$("Houseandtree.gif")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
   hStatus = GdipCreateTexture(pImage, %WrapModeTileFlipX, pTextureBrush)
   hStatus = GdipFillRectangleI(pGraphics, pTextureBrush, 0, 0, 200, 200)

   ' // Get the brush's wrap mode.
   LOCAL wrapMode AS LONG
   hStatus = GdipGetTextureWrapMode(pTextureBrush, wrapMode)

   ' // Create a second texture brush with the same wrap mode.
   strFileName = UCODE$("MyTexture.png")
   hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage2)
   hStatus = GdipCreateTexture(pImage2, wrapMode, pTextureBrush2)
   hStatus = GdipFillRectangleI(pGraphics, pTextureBrush2, 220, 0, 200, 200)

   ' // Cleanup
   IF pImage2 THEN GdipDisposeImage(pImage2)
   IF pTextureBrush2 THEN GdipDeleteBrush(pTextureBrush2)
   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.