我在image上用鼠标画了一个不规则的图像,需要计算面积,大家帮我看看对不对呀呀
用它取得边界
procedure CreateRGN(BorderPointDynArray: array of TPoint): HRGN;
begin
Result := CreatePolygonRgn(BorderPointDynArray[0],
Length(BorderPointDynArray), WINDING);
end;比如点为 APoint,计算到的区域为 ARGN
Result := PtInRegion(ARGN, APoint.x, APoint.y)这样行吗,为什么我得到的总是零呀!!
var
rgn:hrgn;
kk:array[1..1000] of Tpoint;
//kk为得到的坐标点
rgn:=CreateRGN(kk);
for x:=minx to maxx do
for y:=miny to maxy do
if PtInRegion(ARGN, kk[x].x, kk[y].y) then
s:=s+1
用它取得边界
procedure CreateRGN(BorderPointDynArray: array of TPoint): HRGN;
begin
Result := CreatePolygonRgn(BorderPointDynArray[0],
Length(BorderPointDynArray), WINDING);
end;比如点为 APoint,计算到的区域为 ARGN
Result := PtInRegion(ARGN, APoint.x, APoint.y)这样行吗,为什么我得到的总是零呀!!
var
rgn:hrgn;
kk:array[1..1000] of Tpoint;
//kk为得到的坐标点
rgn:=CreateRGN(kk);
for x:=minx to maxx do
for y:=miny to maxy do
if PtInRegion(ARGN, kk[x].x, kk[y].y) then
s:=s+1
你在image上,既然知道了要计算的区域ARGN,那个就遍历一下image上的所有的点在不在这个区域不就行了么
s := 0;
for y := 0 to image.height - 1 do
for x := 0 to image.width - 1 do
if PtInRegion(ARGN, x, y) then inc(s);
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DB, ADODB;type
TForm1 = class(TForm)
Image1: TImage;
ADOQuery1: TADOQuery;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
i,maxX,minX,maxY,minY:integer;
ks:boolean;
kk:array[0..10000] of Tpoint;
rpnt,mpnt:Tpoint; function CreateRGN(BorderPointDynArray: array of TPoint): HRGN;implementation{$R *.dfm}procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ks:=true;
maxx:=x;
minx:=x;
maxy:=y;
miny:=y;
mpnt:=point(x,y);
rpnt:=mpnt;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not (ks) then exit;
image1.Canvas.MoveTo(mpnt.X ,mpnt.Y );
image1.Canvas.LineTo(x,y);
mpnt:=point(x,y );
kk[i].x:=x;
kk[i].Y :=y;
i:=i+1;
if x>maxx then maxx:=x;
if x<minx then minx:=x;
if y>maxy then maxy:=y;
if y<miny then miny:=y;end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
rgn:Hrgn;
s:integer;
begin
if not (ks) then exit;
rgn:= CreateRGN (kk);
for x:=0 to image1.Width-1 do
for y:=0 to image1.Height-1 do
if PtInRegion(RGN, x, y) then inc(s);
caption:=inttostr(s);
s:=0;
ks:=false;end;
function CreateRGN(BorderPointDynArray: array of TPoint): HRGN;
begin
Result := CreatePolygonRgn(BorderPointDynArray[0],
Length(BorderPointDynArray), ALTERNATE);
end;
end.
minx:=x;
maxy:=y;
miny:=y;(movedown里面的)
老大,你这几句写的什么意思啊这点东西写的问题太多了,10000个点够干什么啊?多划拉两下就out bound了