The following example creates a region from a path, gets the region's enclosing rectangle, and then displays both.
C++
VOID Example_GetBoundsRect(HDC hdc)
{
Graphics graphics(hdc);
Point points[] = {
Point(110, 20),
Point(120, 30),
Point(100, 60),
Point(120, 70),
Point(150, 60),
Point(140, 10)};
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
Pen pen(Color(255, 0, 0, 0));
Rect rect;
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Get the region's enclosing rectangle.
pathRegion.GetBounds(&rect, &graphics);
// Show the region and the enclosing rectangle.
graphics.FillRegion(&solidBrush, &pathRegion);
graphics.DrawRectangle(&pen, rect);
}
PowerBASIC
SUB GDIP_GetRegionBounds (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAl pPen AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL rc AS RECTF
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 = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0, %UnitWorld, pPen)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Get the region's enclosing rectangle.
hStatus = GdipGetRegionBounds(pPathRegion, pGraphics, rc)
' // Show the region and the enclosing rectangle.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
hStatus = GdipDrawRectangle(pGraphics, pPen, rc.x, rc.y, rc.Width, rc.Height)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pPathRegion THEN GdipDeleteRegion(pPathRegion)
IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipGetRegionBounds.png)
The following example creates a region from a path, gets the region's enclosing rectangle, and then displays both.
C++
VOID Example_GetBoundsRect(HDC hdc)
{
Graphics graphics(hdc);
Point points[] = {
Point(110, 20),
Point(120, 30),
Point(100, 60),
Point(120, 70),
Point(150, 60),
Point(140, 10)};
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
Pen pen(Color(255, 0, 0, 0));
Rect rect;
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Get the region's enclosing rectangle.
pathRegion.GetBounds(&rect, &graphics);
// Show the region and the enclosing rectangle.
graphics.FillRegion(&solidBrush, &pathRegion);
graphics.DrawRectangle(&pen, rect);
}
PowerBASIC
SUB GDIP_GetRegionBoundsI (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAl pPen AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL rc AS RECTL
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 = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0, %UnitWorld, pPen)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Get the region's enclosing rectangle.
hStatus = GdipGetRegionBoundsI(pPathRegion, pGraphics, rc)
' // Show the region and the enclosing rectangle.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
hStatus = GdipDrawRectangleI(pGraphics, pPen, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pPathRegion THEN GdipDeleteRegion(pPathRegion)
IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipGetRegionBoundsI.png)