请教:GetRgnBox函数能否用来判断两个区域有无交集?用什么函数可以?(50分)

  • 主题发起人 主题发起人 baoling
  • 开始时间 开始时间
B

baoling

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:GetRgnBox函数能否用来判断两个区域有无交集?用什么函数可以?
 
CombineRgn可以
 
我使用GetRgnBox函数总是出错,能否给个例子
 
没用过那个getrgnbox,不过我前几天用了GetRegionData和getpath,你可以看看<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; a_array:array[1..10] of tpoint;<br>&nbsp; h:hrgn;<br>&nbsp; rectdata:PRgnData;<br>&nbsp; li_temp:integer;<br>&nbsp; pint:psmallint;<br>&nbsp; i:integer;<br>&nbsp; r:trect;<br>&nbsp; ppo,<br>&nbsp; ppoo:ppoint;<br>&nbsp; pb:integer;<br>&nbsp; size:integer;<br>begin<br>&nbsp; a_array[1].x:=12;<br>&nbsp; a_array[1].y:=12;<br>&nbsp; a_array[2].x:=100;<br>&nbsp; a_array[2].y:=12;<br>&nbsp; a_array[3].x:=100;<br>&nbsp; a_array[3].y:=200;<br>&nbsp; a_array[4].x:=50;<br>&nbsp; a_array[4].y:=50;<br>&nbsp; a_array[5].x:=312;<br>&nbsp; a_array[5].y:=100;<br>h:=CreatePolygonRgn(a_array,5,WINDING);<br>&nbsp; beginpath(canvas.handle);<br>&nbsp; canvas.Polygon(Slice(a_array, 5));<br>&nbsp; endpath(canvas.handle);<br><br>// &nbsp;getmem(ppoo,sizeof(tpoint));<br>&nbsp; size:=getpath(canvas.handle,ppoo^,pb,0);<br>&nbsp; getmem(ppoo,sizeof(tpoint)*size);<br>&nbsp; getpath(canvas.handle,ppoo^,pb,size);<br>&nbsp; ppo:=ppoo;<br>&nbsp; caption:='';<br>&nbsp; for i:=0 to 4 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; caption:=caption+inttostr(ppoo^.x)+':'+inttostr(ppoo^.y)+':';<br>&nbsp; &nbsp; if i&lt;4 then<br>&nbsp; &nbsp; &nbsp; inc(ppoo,1);<br>&nbsp; &nbsp; end;<br>&nbsp; ppoo:=ppo; <br>&nbsp; freemem(ppoo);<br><br>&nbsp; li_temp:=GetRegionData(h,0,nil);<br>&nbsp; rectdata:=AllocMem(li_temp);<br>&nbsp; GetRegionData(h,li_temp,rectdata);<br>// &nbsp;showmessage(floattostr(rectdata^.rdh.nRgnSize / rectdata^.rdh.nCount));<br>// &nbsp;caption:=floattostr(rectdata^.rdh.nRgnSize / rectdata^.rdh.nCount);<br>&nbsp; pint:=@rectdata^.buffer[0];<br>&nbsp; for i:=0 to rectdata^.rdh.nCount-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; r.Left :=pint^;<br>&nbsp; &nbsp; &nbsp; inc(pint,sizeof(smallint));<br>&nbsp; &nbsp; &nbsp; r.top :=pint^;<br>&nbsp; &nbsp; &nbsp; inc(pint,sizeof(smallint));<br>&nbsp; &nbsp; &nbsp; r.right:=pint^;<br>&nbsp; &nbsp; &nbsp; inc(pint,sizeof(smallint));<br>&nbsp; &nbsp; &nbsp; r.bottom:=pint^;<br>&nbsp; &nbsp; &nbsp; inc(pint,sizeof(smallint));<br>&nbsp; &nbsp; &nbsp; canvas.brush.Color :=clgreen;<br>&nbsp; &nbsp; &nbsp; CANVAS.pen.Color :=clred;<br>&nbsp; &nbsp; &nbsp; canvas.Rectangle(r);<br>&nbsp; end;<br>&nbsp; freemem(rectdata); &nbsp; &nbsp;<br>deleteobject(h);<br>end;<br>end.<br>
 
我用了两个Shape和一个按钮测试了GetRgnBox,测试结果不对,<br><br>unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, ExtCtrls;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; S1: TShape;<br>&nbsp; &nbsp; S2: TShape;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; A:HRgn;<br>&nbsp; R:TRect;<br>&nbsp; u:Integer;<br>begin<br>A := CreateEllipticRgn(S1.Left, S1.Top,S1.Left+S1.Width ,S1.Top+S1.Height);<br>R:=rect(S2.Left, S2.Top,S2.Left+S2.Width ,S2.Top+S2.Height);<br>u:=GetRgnBox(A,r); &nbsp; &nbsp;//如果有交集u的结果是2,3 无交集则是1,但无论怎样都是3<br>label1.Caption:=inttostr(u);<br>end;<br><br>end.<br>
 
The GetRgnBox function retrieves the bounding rectangle of the<br>&nbsp;specified region. <br>这是它的说明,应该是没有取交售的功能的呀
 
GetRgnBox得到包含一个区域的最小的矩形;<br>判断两个区域的交集,一般是根据其中一个区域的边界点是否在另一个区域内,利用 PtInRegion来判断.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
915
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部