如何在image.canvas中画一条带箭头的坐标轴?(50分)

  • 主题发起人 主题发起人 lanchong
  • 开始时间 开始时间
Canvas.LintTo加Canvas.Polygon
 
给你一部分 :)

procedure TForm1.XYCreatebtnClick(Sender: TObject);
var i:integer;
begin
PaintBox1.Refresh;
with PaintBox1.Canvas do
begin
Pen.Width:=2;//坐标轴粗一些
Pen.Color:=clBlack;
MoveTo(30,30); //原点(30,300)
LineTo(30,300); //温度轴即纵轴
LineTo(400,300);//时间轴即横轴
{以下代码画箭头}
MoveTo(25,35);
LineTo(30,30);
LineTo(35,35);
MoveTo(395,295);
LineTo(400,300);
LineTo(395,305);
X.Visible:=true;
Y.Visible:=true;
{以下代码描述坐标轴的虚线格以方便读取坐标}
Pen.Width:=1;
Pen.Color:=clBlack;
Pen.Style:=psDot; //虚线方式
textout(15,305,'0');
for i:=1 to 16 do
begin
moveto(30,(300-15*i));
lineto(390,(300-15*i));
if i mod 2=0 then textout(10,(295-15*i),inttostr(i*5));
end; //这个循环画出了竖直的虚线
for i:=1 to 24 do
begin
moveto((30+i*15),300);
lineto((30+i*15),60);
if i mod 2=0 then textout((25+i*15),305,inttostr(i));
end; //这个循环画出了水平的虚线
haibobtn.Enabled:=true;
XYCreatebtn.Enabled:=false;
end;
end;
 
to wjiachun,
我的moveto(),lineto()里的参数都是变量,用你的办法画箭头好像不太行吧?
 
我只是举一个例子而已
变量你也可以自己类似的计算嘛
 
大富翁让我养成了光提问不动脑的坏习惯了,呵呵……
 
我也变成这样的了光提问不动脑
 
lanchong,wjiachun说对的呀,我上个学期考试时也是交一个需要画坐标的程序,呵呵,我就是用delphi做的
画法和老猫大同小异:
先画直线:
canvas.moveto(20,20);
canvas.lineto(20,200);

画左边分岔:
canvas.moveto(20,20);
canvas.lineto(10,30);
画右边分岔:
canavs.moveto(20,20);
canvas.lineto(30,30);
以上是画Y轴


x 轴如法炮制就完了






 

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
i:=0;
With Image1.Canvas Do
Begin
Pen.Color:=clWindowFrame ;
pen.width:=1;
rectangle(0,0,image1.Width,image1.Height);
Pen.Color:=clBlack;
Pen.Width:=2;
MoveTo(20,20); // 画坐标轴
lineto(20,image1.Height-20);
lineto(image1.width-20,image1.Height-20);

MoveTo(20,20); // 画y箭头
lineto(20-5,20+10);
moveto(20,20);
lineto(20+5,20+10);

MoveTo(image1.width-20,image1.Height-20); // 画x箭头
lineto(image1.width-20-10,image1.Height-20+5);
MoveTo(image1.width-20,image1.Height-20);
lineto(image1.width-20-10,image1.Height-20-5);

textout(10,image1.Height-25,'0');

Pen.Color:=clBlack; //画轴线
pen.Style:=psDot;
Pen.Width:=1;
while image1.Height-40-10*i>15 do begin
inc(i);
MoveTo(20,image1.Height-20-10*i);
lineto(image1.Width-20-20,image1.Height-20-10*i);
if (i mod 5)=0 then textout(10,image1.Height-20-10*i-5,inttostr(i));
end;


end;
end;


 
接受答案了.
 
这种画法一点灵活性没有
应该这条直线是任意角度的
然后在他两端画箭头,才通用
 
后退
顶部