unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;type
  TForm1 = class(TForm)
    Image1: TImage;
    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;
  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;
end;procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  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
  rgn:=  CreateRGN (kk);
  for x:=minx to maxx do
    for y:=miny to maxy do
      if  PtInRegion(rgn, x, y) then
            s:=s+1;
  caption:=inttostr(s);end;
function CreateRGN(BorderPointDynArray: array of TPoint): HRGN;
begin
  Result := CreatePolygonRgn(BorderPointDynArray[0],
  Length(BorderPointDynArray), ALTERNATE);
end;end.
  

解决方案 »

  1.   

    再一个image上画一个任意多边形,然后计算面积
      

  2.   

    当鼠标down的时候要用SetCapture(self.handle) 函数使鼠标归本窗体所有,并且设置一个标志变量为mouse move判断鼠标状态服务,mouse down的时候 ReleaseCapture就可以了。
      

  3.   

    kk:array[0..10000] of Tpoint;够不够大?Image1MouseMove事件中是不是做一下检测
    if ks=false then exit;Image1MouseUp事件中把
    ks:=false;
      

  4.   

    他不是报错,得出的结果不对呀,代码没有问题
    to zhuangbx220数组大小够用,因为图片不大,加不加检测没有关系吧!!!