大家看看下面的代码:
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 呀,难道是我的数组太小了????
解决方案 »
- 关于使用ADOquery1出现的问题?
- 如何在前台编制程序读取串口的数据呀请给我思路或者代码?
- 一个不知道原因的问题!求各位高人解答原因!(100分)
- 请问DBRichEdit / RichEdit 加了右键弹出菜单后就不能按键盘的 Del向后删除字符,如何解决???
- 请问“网络营销”的搜索原理是什么
- 关于DBGrid中控制日期型字段的输入!在线等待!
- 如何像使用ShellAbout那样打开关于对话框来调用任务管理器中的文件-新建任务对话框?需要用什么函数?
- 急:如何获得汉字的内码?
- 三层结构 存储blob失败? 告急 —— 大侠们帮忙,在线等
- SetWindowsHookEx问题?
- 如何让MediaPlayer1.Position识别这样的时间格式:00:38.10
- Delphi中如何屏蔽右键?
数组就有这个问题
当你的数据不是很大的时候,你用数组就感觉是浪费了空间
如果数据很大时候,你用数组肯定是不行的
你的程序中不是用到了指针嘛!
指针就挺好的
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試下