救火!救火!关于实现在图片中划双箭头线和添加备注! 要求在已有图片中标上双箭头线和直线(最好有单箭头直线和曲线),还要在图片的某些地方添加注释说明(多行的,类似memo).实际上就是类似一些画图设计软件对设计图进行设计说明。求助大家帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 组件可以用 dxFlowChart www.51delphi.com 中有下载现成的代码我有一些,你可以看看.lineto(image1.width,trunc(y1)); image1.canvas.moveto(image1.width div 2,0); image1.canvas.lineto(image1.width div 2,image1.height); image1.canvas.pen.style:=psSolid; image1.canvas.Movevar x1,y1:real;begin image1.canvas.Rectangle(0,0,width,height); x1:=0; y1:=(form1.image1.Left+form1.Image1.Width)/4; image1.Canvas.pen.Color:=clRed; image1.canvas.pen.style:=psDash; image1.Canvas.MoveTo(0,trunc(y1)); image1.canvasTo(image1.width-15,trunc(y1)-7); image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo(image1.width-15,trunc(y1)+7); image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo((image1.width div 2)-7,15); image1.canvas.lineto(image1.width div 2,0); image1.canvas.MoveTo((image1.width div 2)+7,15); image1.canvas.lineto(image1.width div 2,0);unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;const Penwidth = 5;//画笔的粗细 Len = 20;//箭头线的长度 {说明:这两个常量应该一起变化,具体值由效果来定。 当Penwidth很小时,显示的效果不是太好}type TForm1 = class(TForm) procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; xs, ys: integer;//画线开始处的坐标 xt, yt: integer;//记录鼠标前一时刻的坐标 xl, yl: integer;//记录第一条箭头线的端点坐标 xr, yr: integer;//记录第二条箭头线的端点坐标 B: boolean;//判断是否已经开始画线implementation{$R *.dfm}procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin {画线结尾时,将线重新填充一遍,以免有部分空白} if not ((x = xs) and (y = ys)) then begin Form1.Canvas.Pen.Mode := pmCopy; Form1.Canvas.Pen.Color := clRed; Form1.Canvas.Pen.Width := PenWidth; Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(x, y); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xr, yr); end; B := False;end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin xs := x; ys := y; xt := x; yt := y; xl := -1; yl := -1; xr := -1; yr := -1; B := True;end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if B then begin Form1.Canvas.Pen.Mode := pmNotXor; Form1.Canvas.Pen.Color := clRed; Form1.Canvas.Pen.Width := PenWidth; Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(xt, yt); Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(x, y); if xl <> -1 then begin Form1.Canvas.MoveTo(xt, yt); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(xt, yt); Form1.Canvas.LineTo(xr, yr); end; xt := x; yt := y; if x > xs then begin xl := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6)); yl := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6)); xr := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6)); yr := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6)); end else if x < xs then begin xl := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6)); yl := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6)); xr := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6)); yr := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6)); end else if y < ys then begin xl := trunc(x - Len * Sin(Pi / 6)); yl := trunc(y + Len * Cos(Pi / 6)); xr := trunc(x + Len * Sin(Pi / 6)); yr := trunc(y + Len * Cos(Pi / 6)); end else if y > ys then begin xl := trunc(x - Len * Sin(Pi / 6)); yl := trunc(y - Len * Cos(Pi / 6)); xr := trunc(x + Len * Sin(Pi / 6)); yr := trunc(y - Len * Cos(Pi / 6)); end else begin xl := -1; yl := -1; xr := -1; yr := -1; end; if xl <> -1 then begin Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xr, yr); end; end;end;procedure TForm1.FormShow(Sender: TObject);begin Form1.Color := clWhite; Form1.Caption := '画带箭头的直线'; Form1.WindowState := wsMaximized; B := False; xt := -1; yt := -1; xl := -1; yl := -1; xr := -1; yr := -1;end;procedure TForm1.FormCreate(Sender: TObject);begin Form1.BorderIcons := [biSystemMenu];end;end.以前收藏的 hehe^^ 箭头不也是线画出来的吗?备注可以用image.Canvas.TextOut加到图片上 CDSoftwareWj(95927) :你贴的内容恰好我也看到了。呵呵。这几天终于把所有图片的问题迎刃而解。我把双箭头画线的代码也写上。 var FGud_GudEdit: TFGud_GudEdit; xs, ys: integer;//画线开始处的坐标 xt, yt: integer;//记录鼠标前一时刻的坐标 xl, yl: integer;//记录第一条箭头线的端点坐标 xr, yr: integer;//记录第二条箭头线的端点坐标 x3,y3:integer; //第二个箭头 x4,y4:integer; //第二个箭头 b: boolean;//判断是否已经开始画线 dx,dy,tx,ty:integer; //拖动用到的坐标; 注释坐标procedure TFGud_GudEdit.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if shift=[ssleft] then begin xs := x; ys := y; xt := x; yt := y; xl := -1; yl := -1; xr := -1; yr := -1; b := True; image1.Picture.SaveToFile('C:\Documents and Settings\Administrator\My Documents\temp\2.bmp'); //bitbtn3.Enabled:=true; end;end;procedure TFGud_GudEdit.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if b then begin image1.Canvas.Pen.Mode := pmNotXor; image1.Canvas.Pen.Color := cd1.Color; image1.Canvas.Pen.Width := Sedit1.Value; image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(xt, yt); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x, y);//[--- if r2.Checked then begin xt := x; yt := y; end; if r1.Checked then begin//---] if xl <> -1 then begin image1.Canvas.MoveTo(xt, yt); image1.Canvas.LineTo(xl, yl); image1.Canvas.MoveTo(xt, yt); image1.Canvas.LineTo(xr, yr);//[-- image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x3, y3); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x4, y4);//--] end; xt := x; yt := y; if x > xs then begin xl := trunc(x + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); yl := trunc(y - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); xr := trunc(x + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); yr := trunc(y - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xl, yl); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xr, yr); //[-- x3 := trunc(xs -Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); y3 := trunc(ys + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); x4 := trunc(xs - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); y4 := trunc(ys +Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x3, y3); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x4, y4); //--] end else if x < xs then begin xl := trunc(x - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); yl := trunc(y + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); xr := trunc(x - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); yr := trunc(y + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xl, yl); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xr, yr); //[-- x3 := trunc(xs +Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); y3 := trunc(ys - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6)); x4 := trunc(xs + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); y4 := trunc(ys - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6)); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x3, y3); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x4, y4); //--] end else if y < ys then begin xl := trunc(x + Len * Sin(Pi / 6)); yl := trunc(y + Len * Cos(Pi / 6)); xr := trunc(x - Len * Sin(Pi / 6)); yr := trunc(y + Len * Cos(Pi / 6)); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xl, yl); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xr, yr); //[-- x3 := trunc(xs + Len * Sin(Pi / 6)); y3 := trunc(ys - Len * Cos(Pi / 6)); x4 := trunc(xs - Len * Sin(Pi / 6)); y4 := trunc(ys - Len * Cos(Pi / 6)); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x3, y3); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x4, y4); //--] end else begin xl := trunc(x + Len * Sin(Pi / 6)); yl := trunc(y - Len * Cos(Pi / 6)); xr := trunc(x - Len * Sin(Pi / 6)); yr := trunc(y - Len * Cos(Pi / 6)); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xl, yl); image1.Canvas.MoveTo(x, y); image1.Canvas.LineTo(xr, yr); //[-- x3 := trunc(xs + Len * Sin(Pi / 6)); y3 := trunc(ys + Len * Cos(Pi / 6)); x4 := trunc(xs - Len * Sin(Pi / 6)); y4 := trunc(ys + Len * Cos(Pi / 6)); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x3, y3); image1.Canvas.MoveTo(xs, ys); image1.Canvas.LineTo(x4, y4); //--] end; end; end; //--end;procedure TFGud_GudEdit.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin b := False;end; 还有,画线的时候,图片背景一闪,一闪的(像黑夜的流星#$%^&*):D不知道怎么解决。 组件可以用 dxFlowChart www.51delphi.com 中有下载现成的代码我有一些,你可以看看.lineto(image1.width,trunc(y1)); image1.canvas.moveto(image1.width div 2,0); image1.canvas.lineto(image1.width div 2,image1.height); image1.canvas.pen.style:=psSolid; image1.canvas.Movevar x1,y1:real;begin image1.canvas.Rectangle(0,0,width,height); x1:=0; y1:=(form1.image1.Left+form1.Image1.Width)/4; image1.Canvas.pen.Color:=clRed; image1.canvas.pen.style:=psDash; image1.Canvas.MoveTo(0,trunc(y1)); image1.canvasTo(image1.width-15,trunc(y1)-7); image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo(image1.width-15,trunc(y1)+7); image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo((image1.width div 2)-7,15); image1.canvas.lineto(image1.width div 2,0); image1.canvas.MoveTo((image1.width div 2)+7,15); image1.canvas.lineto(image1.width div 2,0);unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;const Penwidth = 5;//画笔的粗细 Len = 20;//箭头线的长度 {说明:这两个常量应该一起变化,具体值由效果来定。 当Penwidth很小时,显示的效果不是太好}type TForm1 = class(TForm) procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; xs, ys: integer;//画线开始处的坐标 xt, yt: integer;//记录鼠标前一时刻的坐标 xl, yl: integer;//记录第一条箭头线的端点坐标 xr, yr: integer;//记录第二条箭头线的端点坐标 B: boolean;//判断是否已经开始画线implementation{$R *.dfm}procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin {画线结尾时,将线重新填充一遍,以免有部分空白} if not ((x = xs) and (y = ys)) then begin Form1.Canvas.Pen.Mode := pmCopy; Form1.Canvas.Pen.Color := clRed; Form1.Canvas.Pen.Width := PenWidth; Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(x, y); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xr, yr); end; B := False;end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin xs := x; ys := y; xt := x; yt := y; xl := -1; yl := -1; xr := -1; yr := -1; B := True;end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if B then begin Form1.Canvas.Pen.Mode := pmNotXor; Form1.Canvas.Pen.Color := clRed; Form1.Canvas.Pen.Width := PenWidth; Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(xt, yt); Form1.Canvas.MoveTo(xs, ys); Form1.Canvas.LineTo(x, y); if xl <> -1 then begin Form1.Canvas.MoveTo(xt, yt); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(xt, yt); Form1.Canvas.LineTo(xr, yr); end; xt := x; yt := y; if x > xs then begin xl := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6)); yl := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6)); xr := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6)); yr := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6)); end else if x < xs then begin xl := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6)); yl := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6)); xr := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6)); yr := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6)); end else if y < ys then begin xl := trunc(x - Len * Sin(Pi / 6)); yl := trunc(y + Len * Cos(Pi / 6)); xr := trunc(x + Len * Sin(Pi / 6)); yr := trunc(y + Len * Cos(Pi / 6)); end else if y > ys then begin xl := trunc(x - Len * Sin(Pi / 6)); yl := trunc(y - Len * Cos(Pi / 6)); xr := trunc(x + Len * Sin(Pi / 6)); yr := trunc(y - Len * Cos(Pi / 6)); end else begin xl := -1; yl := -1; xr := -1; yr := -1; end; if xl <> -1 then begin Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xl, yl); Form1.Canvas.MoveTo(x, y); Form1.Canvas.LineTo(xr, yr); end; end;end;procedure TForm1.FormShow(Sender: TObject);begin Form1.Color := clWhite; Form1.Caption := '画带箭头的直线'; Form1.WindowState := wsMaximized; B := False; xt := -1; yt := -1; xl := -1; yl := -1; xr := -1; yr := -1;end;procedure TForm1.FormCreate(Sender: TObject);begin Form1.BorderIcons := [biSystemMenu];end;end.以前收藏的 hehe^^ rave做的报表如何能让最终用户也能修改,谢谢 关于mediaplayer控件播放在线文件的问题 dbgrid的问题,谢谢 请教 关于托盘程序 关于DeleteFile函数的问题?急(在线等待) delphi的菜单怎么加入分隔线? 请赐教! 如何用delphi代码从winsocket服务器上下载文件? delphi大神请看,来个非常非常诡异的问题! 还差一分就穿五条裤衩,不爽呀 使用 Locate 有问题 请指教
image1.canvas.lineto(image1.width div 2,image1.height); image1.canvas.pen.style:=psSolid; image1.canvas.Movevar
x1,y1:real;
begin
image1.canvas.Rectangle(0,0,width,height);
x1:=0;
y1:=(form1.image1.Left+form1.Image1.Width)/4;
image1.Canvas.pen.Color:=clRed;
image1.canvas.pen.style:=psDash; image1.Canvas.MoveTo(0,trunc(y1));
image1.canvasTo(image1.width-15,trunc(y1)-7);
image1.canvas.lineto(image1.width,trunc(y1));
image1.canvas.MoveTo(image1.width-15,trunc(y1)+7);
image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo((image1.width div 2)-7,15);
image1.canvas.lineto(image1.width div 2,0);
image1.canvas.MoveTo((image1.width div 2)+7,15);
image1.canvas.lineto(image1.width div 2,0);unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;const
Penwidth = 5;//画笔的粗细
Len = 20;//箭头线的长度
{说明:这两个常量应该一起变化,具体值由效果来定。
当Penwidth很小时,显示的效果不是太好}type
TForm1 = class(TForm)
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
xs, ys: integer;//画线开始处的坐标
xt, yt: integer;//记录鼠标前一时刻的坐标
xl, yl: integer;//记录第一条箭头线的端点坐标
xr, yr: integer;//记录第二条箭头线的端点坐标
B: boolean;//判断是否已经开始画线implementation{$R *.dfm}procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
{画线结尾时,将线重新填充一遍,以免有部分空白}
if not ((x = xs) and (y = ys)) then
begin
Form1.Canvas.Pen.Mode := pmCopy;
Form1.Canvas.Pen.Color := clRed;
Form1.Canvas.Pen.Width := PenWidth;
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(x, y);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xr, yr);
end; B := False;
end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
xs := x;
ys := y;
xt := x;
yt := y;
xl := -1;
yl := -1;
xr := -1;
yr := -1;
B := True;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if B then
begin
Form1.Canvas.Pen.Mode := pmNotXor;
Form1.Canvas.Pen.Color := clRed;
Form1.Canvas.Pen.Width := PenWidth;
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(xt, yt);
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(x, y);
if xl <> -1 then
begin
Form1.Canvas.MoveTo(xt, yt);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(xt, yt);
Form1.Canvas.LineTo(xr, yr);
end;
xt := x;
yt := y;
if x > xs then
begin
xl := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6));
yl := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6));
xr := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6));
yr := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6));
end
else
if x < xs then
begin
xl := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6));
yl := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6));
xr := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6));
yr := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6));
end
else
if y < ys then
begin
xl := trunc(x - Len * Sin(Pi / 6));
yl := trunc(y + Len * Cos(Pi / 6));
xr := trunc(x + Len * Sin(Pi / 6));
yr := trunc(y + Len * Cos(Pi / 6));
end
else
if y > ys then
begin
xl := trunc(x - Len * Sin(Pi / 6));
yl := trunc(y - Len * Cos(Pi / 6));
xr := trunc(x + Len * Sin(Pi / 6));
yr := trunc(y - Len * Cos(Pi / 6));
end
else
begin
xl := -1;
yl := -1;
xr := -1;
yr := -1;
end;
if xl <> -1 then
begin
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xr, yr);
end;
end;
end;procedure TForm1.FormShow(Sender: TObject);
begin
Form1.Color := clWhite;
Form1.Caption := '画带箭头的直线';
Form1.WindowState := wsMaximized;
B := False;
xt := -1;
yt := -1;
xl := -1;
yl := -1;
xr := -1;
yr := -1;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.BorderIcons := [biSystemMenu];
end;end.以前收藏的 hehe^^
备注可以用image.Canvas.TextOut加到图片上
你贴的内容恰好我也看到了。呵呵。这几天终于把所有图片的问题迎刃而解。
我把双箭头画线的代码也写上。
FGud_GudEdit: TFGud_GudEdit;
xs, ys: integer;//画线开始处的坐标
xt, yt: integer;//记录鼠标前一时刻的坐标
xl, yl: integer;//记录第一条箭头线的端点坐标
xr, yr: integer;//记录第二条箭头线的端点坐标
x3,y3:integer; //第二个箭头
x4,y4:integer; //第二个箭头
b: boolean;//判断是否已经开始画线 dx,dy,tx,ty:integer; //拖动用到的坐标; 注释坐标procedure TFGud_GudEdit.Image1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if shift=[ssleft] then
begin
xs := x;
ys := y;
xt := x;
yt := y;
xl := -1;
yl := -1;
xr := -1;
yr := -1;
b := True;
image1.Picture.SaveToFile('C:\Documents and Settings\Administrator\My Documents\temp\2.bmp');
//bitbtn3.Enabled:=true;
end;end;procedure TFGud_GudEdit.Image1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if b then
begin
image1.Canvas.Pen.Mode := pmNotXor;
image1.Canvas.Pen.Color := cd1.Color;
image1.Canvas.Pen.Width := Sedit1.Value;
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(xt, yt);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x, y);
//[---
if r2.Checked then
begin
xt := x;
yt := y;
end;
if r1.Checked then
begin
//---]
if xl <> -1 then
begin
image1.Canvas.MoveTo(xt, yt);
image1.Canvas.LineTo(xl, yl);
image1.Canvas.MoveTo(xt, yt);
image1.Canvas.LineTo(xr, yr);
//[--
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x3, y3);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x4, y4);
//--]
end;
xt := x;
yt := y;
if x > xs then
begin
xl := trunc(x + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
yl := trunc(y - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
xr := trunc(x + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
yr := trunc(y - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xl, yl);
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xr, yr); //[--
x3 := trunc(xs -Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
y3 := trunc(ys + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
x4 := trunc(xs - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
y4 := trunc(ys +Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x3, y3);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x4, y4);
//--] end
else
if x < xs then
begin
xl := trunc(x - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
yl := trunc(y + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
xr := trunc(x - Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
yr := trunc(y + Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xl, yl);
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xr, yr); //[--
x3 := trunc(xs +Len * Cos(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
y3 := trunc(ys - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) + Pi / 6));
x4 := trunc(xs + Len * Cos(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
y4 := trunc(ys - Len * Sin(pi - ArcTan((y - ys) / (x - xs)) - Pi / 6));
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x3, y3);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x4, y4);
//--]
end
else
if y < ys then
begin
xl := trunc(x + Len * Sin(Pi / 6));
yl := trunc(y + Len * Cos(Pi / 6));
xr := trunc(x - Len * Sin(Pi / 6));
yr := trunc(y + Len * Cos(Pi / 6));
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xl, yl);
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xr, yr); //[--
x3 := trunc(xs + Len * Sin(Pi / 6));
y3 := trunc(ys - Len * Cos(Pi / 6));
x4 := trunc(xs - Len * Sin(Pi / 6));
y4 := trunc(ys - Len * Cos(Pi / 6));
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x3, y3);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x4, y4);
//--] end
else
begin
xl := trunc(x + Len * Sin(Pi / 6));
yl := trunc(y - Len * Cos(Pi / 6));
xr := trunc(x - Len * Sin(Pi / 6));
yr := trunc(y - Len * Cos(Pi / 6));
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xl, yl);
image1.Canvas.MoveTo(x, y);
image1.Canvas.LineTo(xr, yr); //[--
x3 := trunc(xs + Len * Sin(Pi / 6));
y3 := trunc(ys + Len * Cos(Pi / 6));
x4 := trunc(xs - Len * Sin(Pi / 6));
y4 := trunc(ys + Len * Cos(Pi / 6));
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x3, y3);
image1.Canvas.MoveTo(xs, ys);
image1.Canvas.LineTo(x4, y4);
//--]
end;
end;
end; //--end;procedure TFGud_GudEdit.Image1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
b := False;end;
不知道怎么解决。
组件可以用 dxFlowChart www.51delphi.com 中有下载现成的代码我有一些,你可以看看.lineto(image1.width,trunc(y1)); image1.canvas.moveto(image1.width div 2,0);
image1.canvas.lineto(image1.width div 2,image1.height); image1.canvas.pen.style:=psSolid; image1.canvas.Movevar
x1,y1:real;
begin
image1.canvas.Rectangle(0,0,width,height);
x1:=0;
y1:=(form1.image1.Left+form1.Image1.Width)/4;
image1.Canvas.pen.Color:=clRed;
image1.canvas.pen.style:=psDash; image1.Canvas.MoveTo(0,trunc(y1));
image1.canvasTo(image1.width-15,trunc(y1)-7);
image1.canvas.lineto(image1.width,trunc(y1));
image1.canvas.MoveTo(image1.width-15,trunc(y1)+7);
image1.canvas.lineto(image1.width,trunc(y1)); image1.canvas.MoveTo((image1.width div 2)-7,15);
image1.canvas.lineto(image1.width div 2,0);
image1.canvas.MoveTo((image1.width div 2)+7,15);
image1.canvas.lineto(image1.width div 2,0);unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;const
Penwidth = 5;//画笔的粗细
Len = 20;//箭头线的长度
{说明:这两个常量应该一起变化,具体值由效果来定。
当Penwidth很小时,显示的效果不是太好}type
TForm1 = class(TForm)
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
xs, ys: integer;//画线开始处的坐标
xt, yt: integer;//记录鼠标前一时刻的坐标
xl, yl: integer;//记录第一条箭头线的端点坐标
xr, yr: integer;//记录第二条箭头线的端点坐标
B: boolean;//判断是否已经开始画线implementation{$R *.dfm}procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
{画线结尾时,将线重新填充一遍,以免有部分空白}
if not ((x = xs) and (y = ys)) then
begin
Form1.Canvas.Pen.Mode := pmCopy;
Form1.Canvas.Pen.Color := clRed;
Form1.Canvas.Pen.Width := PenWidth;
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(x, y);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xr, yr);
end; B := False;
end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
xs := x;
ys := y;
xt := x;
yt := y;
xl := -1;
yl := -1;
xr := -1;
yr := -1;
B := True;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if B then
begin
Form1.Canvas.Pen.Mode := pmNotXor;
Form1.Canvas.Pen.Color := clRed;
Form1.Canvas.Pen.Width := PenWidth;
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(xt, yt);
Form1.Canvas.MoveTo(xs, ys);
Form1.Canvas.LineTo(x, y);
if xl <> -1 then
begin
Form1.Canvas.MoveTo(xt, yt);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(xt, yt);
Form1.Canvas.LineTo(xr, yr);
end;
xt := x;
yt := y;
if x > xs then
begin
xl := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6));
yl := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6));
xr := trunc(x - Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6));
yr := trunc(y - Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6));
end
else
if x < xs then
begin
xl := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) - Pi / 6));
yl := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) - Pi / 6));
xr := trunc(x + Len * Cos(ArcTan((y - ys) / (x - xs)) + Pi / 6));
yr := trunc(y + Len * Sin(ArcTan((y - ys) / (x - xs)) + Pi / 6));
end
else
if y < ys then
begin
xl := trunc(x - Len * Sin(Pi / 6));
yl := trunc(y + Len * Cos(Pi / 6));
xr := trunc(x + Len * Sin(Pi / 6));
yr := trunc(y + Len * Cos(Pi / 6));
end
else
if y > ys then
begin
xl := trunc(x - Len * Sin(Pi / 6));
yl := trunc(y - Len * Cos(Pi / 6));
xr := trunc(x + Len * Sin(Pi / 6));
yr := trunc(y - Len * Cos(Pi / 6));
end
else
begin
xl := -1;
yl := -1;
xr := -1;
yr := -1;
end;
if xl <> -1 then
begin
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xl, yl);
Form1.Canvas.MoveTo(x, y);
Form1.Canvas.LineTo(xr, yr);
end;
end;
end;procedure TForm1.FormShow(Sender: TObject);
begin
Form1.Color := clWhite;
Form1.Caption := '画带箭头的直线';
Form1.WindowState := wsMaximized;
B := False;
xt := -1;
yt := -1;
xl := -1;
yl := -1;
xr := -1;
yr := -1;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.BorderIcons := [biSystemMenu];
end;end.以前收藏的 hehe^^