大家看看下面的代码:
FormMouseDown:  self.DoubleBuffered :=true;
  Drawing := True;
  picimg.Canvas.MoveTo(x,y);  //注:picimg是一个image的控件
  movepnt :=point(x,y);
  originpnt:=movepnt;FormMouseMove:
    PICimg.Canvas.LineTo(x,y);
    picimg.Canvas.MoveTo(x,y);
    new(xypnt);
    xypnt^[xy_i].x:=X ;
    xypnt^[xy_i].y :=y ;
    xy_i:=xy_i+1;FormMouseUp:          picimg.Canvas.MoveTo(movepnt.X,movepnt.y);
          picimg.Canvas.LineTo(x,y);
          renyixing:=AreaOfPolygon (xypnt,xy_i);
          //caption := format('the result is %f', [renyixing]);
          dispose(xypnt);///////////////////////////////////////////////////////////////
const MaxPointNum = 65535;
type
  PXY = ^TXY;
  TXY = record
  x, y: single;
end;
  XYArray = array[0..MaxPointNum] of TXY;
  PXYArray = ^XYArray;// 线/面的数据结构function AreaOfPolygon(xys: PXYArray; nn: integer):single;
var ii:integer;
ss: single;
begin
  ss := 0;
    for ii := 0 to nn-2 do
      ss := ss + (xys^[ii].y+xys^[ii+1].y) * (xys^[ii].x-xys^[ii+1].x) / 2;
    result := abs(ss);
end;只想上面代码的时候image中没有图像什么问题也没有,如果有图像有时候回报
floating point overflow 呀,难道是我的数组太小了????

解决方案 »

  1.   

    floating point overflow那估计就是你的数组定义的太小了
    数组就有这个问题
    当你的数据不是很大的时候,你用数组就感觉是浪费了空间
    如果数据很大时候,你用数组肯定是不行的
    你的程序中不是用到了指针嘛!
    指针就挺好的
      

  2.   

    const MaxPointNum = 65535;
    type
      PXY = ^TXY;
      TXY = record
      x, y: single;
    end;
      XYArray = array[0..MaxPointNum] of TXY;
      PXYArray = ^XYArray;//¡@?/­±ªº?Õu?ÌÛ
      var
      Drawing: boolean;
      movepnt, originpnt: TPoint;
      xypnt: PXYArray;
      xy_i: integer;
      renyixing: single;function AreaOfPolygon(xys: PXYArray; nn: integer):single;
    var ii:integer;
    ss: single;
    begin
      ss := 0;
        for ii := 0 to nn-2 do
          ss := ss + (xys^[ii].y+xys^[ii+1].y) * (xys^[ii].x-xys^[ii+1].x) / 2;
        result := abs(ss);
    end;procedure TForm1.picimgMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        self.DoubleBuffered :=true;
      Drawing := True;
      picimg.Canvas.MoveTo(x,y);  //ª`¡Gpicimg¬O¤@?imageªº±±¥ó
      movepnt :=point(x,y);
      originpnt:=movepnt;
    end;procedure TForm1.picimgMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
        PICimg.Canvas.LineTo(x,y);
        picimg.Canvas.MoveTo(x,y);    new(xypnt);
        xypnt^[xy_i].x:=X ;
        xypnt^[xy_i].y :=y ;
        xy_i:=xy_i+1;
    end;procedure TForm1.picimgMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
              picimg.Canvas.MoveTo(movepnt.X,movepnt.y);
              picimg.Canvas.LineTo(x,y);
              renyixing:=AreaOfPolygon (xypnt,xy_i);
              //caption := format('the result is %f', [renyixing]);
              dispose(xypnt);
    end;
      

  3.   

    代碼我沒改, 發現, 如果你image是裝載了 bmp 就沒問題, 
    如果用其它的圖片格式就不行了!
    所以, 簡單的解決方法, 就將其它的圖片格式轉為 bmp, 再裝到image中
      

  4.   

    我装的是bmp的图片呀!!!是直接截的图片,就是bmp的呀!!想不通了
      

  5.   

    不是数组的大小不够,我估计可能是因为你定义的数组类型为整型
    对图象尤其是真彩24位bmp图操作时,你的数组必须应该使用长整型!
      

  6.   

    原先我在c++builder中做图象处理的时候碰到过类似的问题,仔细检查你的数据定义部分,相信我没错的
      

  7.   

    數組長度, 如果你不是畫很久, 是足夠的, 
    從你說的沒裝圖片正常也可看出沒問題!然後, 數組處理的Mousedown , move, up 得到的TPoint 都是整數, 應該沒問題!我用我貼出來的代碼, 用jpg 試是不行的, 
    但用bmp試, 很正常!!
    你可改多几張bmp試下