The following example creates two regions, one from a path and the other from a rectangle. The code then uses the rectangular region to update the path region. The updated region is the union of the two regions.
C++
VOID Example_UnionReg(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)};
Rect rect(65, 15, 70, 45);
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Create a region from a rectangle.
Region rectRegion(rect);
// Form the union of the two regions.
pathRegion.Union(&rectRegion);
graphics.FillRegion(&solidBrush, &pathRegion);
}
PowerBASIC
SUB GDIP_CombineRegionRegion (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL pRectRegion AS DWORD
LOCAL rc AS RECTL
DIM pts(5) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
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
SetRect rc, 65, 15, 70, 45
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Create a region from a rectangle.
hStatus = GdipCreateRegionRectI(rc, pRectRegion)
' // Form the union of the region and a rectangle.
hStatus = GdipCombineRegionRegion(pPathRegion, pRectRegion, %CombineModeUnion)
' // Fill the union of the two regions with a semitransparent blue brush.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
' // Cleanup
IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
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/GdipCombineRegionRegion.png)
The following example creates two regions, one from a path and the other from a rectangle. The code then uses the rectangular region to update the path region.
C++
VOID Example_XorReg(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)};
Rect rect(65, 15, 70, 45);
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Create a region from a rectangle.
Region rectRegion(rect);
// Perform an exclusive OR operation on the two regions.
pathRegion.Xor(&rectRegion);
graphics.FillRegion(&solidBrush, &pathRegion);
}
PowerBASIC
SUB GDIP_CombineRegionRegion (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL pRectRegion AS DWORD
LOCAL rc AS RECTL
DIM pts(5) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
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
SetRect rc, 65, 15, 70, 45
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Create a region from a rectangle.
hStatus = GdipCreateRegionRectI(rc, pRectRegion)
' // Perform an exclusive OR operation on the two regions.
hStatus = GdipCombineRegionRegion(pPathRegion, pRectRegion, %CombineModeXor)
' // Fill the union of the two regions with a semitransparent blue brush.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
' // Cleanup
IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
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/GdipCombineRegionRegion2.png)
The following example creates a region from a rectangle and a region from a path. Then the code uses the path region to update the rectangular region.
C++
VOID Example_XorReg(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)};
Rect rect(65, 15, 70, 45);
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Create a region from a rectangle.
Region rectRegion(rect);
// Update the rectangular region so that it consists of all points inside
// the path region but outside the rectangular region.
rectRegion.Complement(&pathRegion);
graphics.FillRegion(&solidBrush, &pathRegion);
}
PowerBASIC
SUB GDIP_CombineRegionRegion (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL pRectRegion AS DWORD
LOCAL rc AS RECTL
DIM pts(5) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
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
SetRect rc, 65, 15, 70, 45
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Create a region from a rectangle.
hStatus = GdipCreateRegionRectI(rc, pRectRegion)
' // Update the rectangular region so that it consists of all points inside
' // the path region but outside the rectangular region.
hStatus = GdipCombineRegionRegion(pPathRegion, pRectRegion, %CombineModeComplement)
' // Fill the union of the two regions with a semitransparent blue brush.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
' // Cleanup
IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
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/GdipCombineRegionRegion3.png)
The following example creates two regions, one from a rectangle and the other from a path. Then the code uses the rectangular region to update the path region.
C++
VOID Example_ExcludeReg(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)};
Rect rect(65, 15, 70, 45);
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
path.AddClosedCurve(points, 6);
// Create a region from a rectangle.
Region rectRegion(rect);
// Create a region from a path.
Region pathRegion(&path);
// Exclude a rectangle region from the path region.
pathRegion.Exclude(&rectRegion);
graphics.FillRegion(&solidBrush, &pathRegion);
}
PowerBASIC
SUB GDIP_CombineRegionRegion (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL pRectRegion AS DWORD
LOCAL rc AS RECTL
DIM pts(5) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
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
SetRect rc, 65, 15, 70, 45
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Create a region from a rectangle.
hStatus = GdipCreateRegionRectI(rc, pRectRegion)
' // Exclude a rectangle region from the path region.
hStatus = GdipCombineRegionRegion(pPathRegion, pRectRegion, %CombineModeExclude)
' // Fill the union of the two regions with a semitransparent blue brush.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
' // Cleanup
IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
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/GdipCombineRegionRegion4.png)
The following example creates a region from a path and then uses a rectangle to update the region.
C++
VOID Example_IntersectReg(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)};
Rect rect(65, 15, 70, 45);
GraphicsPath path;
SolidBrush solidBrush(Color(255, 255, 0, 0));
path.AddClosedCurve(points, 6);
// Create a region from a path.
Region pathRegion(&path);
// Create a region from a rectangle.
Region rectRegion(rect);
// Update the region to the portion that intersects with another region.
pathRegion.Intersect(&rectRegion);
graphics.FillRegion(&solidBrush, &pathRegion);
}
PowerBASIC
SUB GDIP_CombineRegionRegion (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pSolidBrush AS DWORD
LOCAL pPathRegion AS DWORD
LOCAL pRectRegion AS DWORD
LOCAL rc AS RECTL
DIM pts(5) AS POINTL
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)
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
SetRect rc, 65, 15, 70, 45
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)
' // Create a region from a path.
hStatus = GdipCreateRegionPath(pPath, pPathRegion)
' // Create a region from a rectangle.
hStatus = GdipCreateRegionRectI(rc, pRectRegion)
' // Exclude a rectangle region from the path region.
hStatus = GdipCombineRegionRegion(pPathRegion, pRectRegion, %CombineModeIntersect)
' // Fill the union of the two regions with a semitransparent blue brush.
hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)
' // Cleanup
IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
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/GdipCombineRegionRegion5.png)