• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetRegionDataSize

Started by José Roca, June 26, 2008, 05:06:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a region from a path and then gets the data that describes the region.

C++


VOID Example_GetData(HDC)

{
   Point points[] = {
      Point(110, 20)
      Point(120, 30),
      Point(100, 60),
      Point(120, 70),
      Point(150, 60),
      Point(140, 10)};
   GraphicsPath path;
   path.AddClosedCurve(points, 6);
   
   // Create a region from a path.
   Region pathRegion(&path);
     
   // Get the region data.
   UINT bufferSize = 0;
   UINT sizeFilled = 0;
   BYTE* pData = NULL;
   
   bufferSize = pathRegion.GetDataSize();
   
   pData = new BYTE[bufferSize];
   pathRegion.GetData(pData, bufferSize, &sizeFilled);
   
   // Inspect or use the region data.
   ...
   delete pData;
}


PowerBASIC


SUB GDIP_GetRegionDataSize (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pPathRegion AS DWORD
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   pts(0).x = 110 : pts(0).y = 20
   pts(1).x = 120 : pts(1).y = 30
   pts(2).x = 100 : pts(2).y = 60
   pts(3).x = 120 : pts(3).y = 70
   pts(4).x = 150 : pts(4).y = 60
   pts(5).x = 140 : pts(5).y = 10

   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)

   ' // Create a region from a path.
   hStatus = GdipCreateRegionPath(pPath, pPathRegion)

   ' // Get the region data.
   LOCAL bufferSize AS DWORD
   LOCAL sizeFilled AS DWORD

   hStatus = GdipGetRegionDataSize(pPathRegion, bufferSize)

   ' // Cleanup
   IF pPathRegion THEN GdipDeleteRegion(pPathRegion)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB