大家看看下面的代码:
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 呀,难道是我的数组太小了????
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 呀,难道是我的数组太小了????
数组就有这个问题
当你的数据不是很大的时候,你用数组就感觉是浪费了空间
如果数据很大时候,你用数组肯定是不行的
你的程序中不是用到了指针嘛!
指针就挺好的
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;
如果用其它的圖片格式就不行了!
所以, 簡單的解決方法, 就將其它的圖片格式轉為 bmp, 再裝到image中
对图象尤其是真彩24位bmp图操作时,你的数组必须应该使用长整型!
從你說的沒裝圖片正常也可看出沒問題!然後, 數組處理的Mousedown , move, up 得到的TPoint 都是整數, 應該沒問題!我用我貼出來的代碼, 用jpg 試是不行的,
但用bmp試, 很正常!!
你可改多几張bmp試下