Originally this example is to get the details of the zone, but unfortunately, this version of GDI + header file less defined a Tregiondata class!
But it does not matter, through the tregiondata is mainly to get the rectangular data in the region, Getregionscans function can complete this task!
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;
Type
TForm1 = Class (Tform)
Procedure Formpaint (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
B:tgpsolidbrush;
Path:tgpgraphicspath;
Rgn1,rgn2:tgpregion;
Rgndata:pbyte;
Rt:tgprect;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = tgppen.create (aclred);
B: = Tgpsolidbrush.create (Makecolor (50, 0, 0, 255));
{Create and populate the first zone}
Path: = Tgpgraphicspath.create;
Path. AddEllipse (Makerect, ClientWidth-40, ClientHeight-40));
RGN1: = tgpregion.create (path);
G.fillregion (b, rgn1);
{Create a second zone from data in the first zone}
Getmem (Rgndata, Rgn1. Getdatasize); {Allocate Space}
Rgn1. GetData (Rgndata, Rgn1. Getdatasize); {Get Data}
RGN2: = Tgpregion.create (Rgndata, Rgn1. Getdatasize); {Create a second zone}
Rgn2. GetBounds (RT, G); {Gets the rectangular range of the second range}
G.drawrectangle (P, RT); {Draw this rectangle}
Freemem (Rgndata); {Free memory}
{If not to test GetData, the following three lines can replace the top six lines}
RGN2: = Rgn1. Clone;
Rgn2. GetBounds (RT, G);
G.drawrectangle (P, RT);
Rgn1. Free;
Rgn2. Free;
Path. Free;
B.free;
P.free;
G.free;
End
End.
Form file:object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 171
ClientWidth = 243
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end