怎样在Image图像上画线 (100分)

  • 主题发起人 主题发起人 joybird
  • 开始时间 开始时间
J

joybird

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位大富翁:<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; 怎样在Image图像上画线,然后又怎样擦去!
 
moveto()<br>lineto()<br>画线<br>XOR 去掉
 
image1.Canvas.Pen.Color:=clred;<br>image1.Canvas.MoveTo(x1,y1);<br>image1.Canvas.LineTo(x2,y2);
 
image中继承了Canvas,在Canvas中你可以根据自己的需要画图或是改变pen、brush<br>image.Canvas.MoveTo(x1,y1);<br>image.Canvas.LineTo(x2,y2);<br>具体的你可以查查帮助中的Tcanvas<br>
 
1.画线<br>Program Files/Borland/Delphi5/Demos/Doc/Graphex<br>......<br>&nbsp; &nbsp; case DrawingTool of<br>&nbsp; &nbsp; &nbsp; dtLine:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Image.Canvas.MoveTo(TopLeft.X, TopLeft.Y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Image.Canvas.LineTo(BottomRight.X, BottomRight.Y);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>......<br>--------------------------------------------------<br><br>2.怎样擦去<br><br>procedure TForm1.SpeedButton27Click(Sender: TObject);<br>begin<br>DrawingTool := dtRubber;<br>Screen.Cursors[crMyCursor] := LoadCursor (hInstance,'CURSOR_1');<br>Image.Cursor := crMyCursor;<br>end;<br>......<br>case DrawingTool of<br>&nbsp; &nbsp; &nbsp; &nbsp;dtRubber:<br>&nbsp; &nbsp; &nbsp; &nbsp; if Flag then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Image.Canvas.FillRect(Rect(StartX,StartY,StartX+10,StartY+10));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br>......<br>
 
moveto<br>linto<br>notxor
 
以下程序在Image上画线,按右键清除.<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Image1: TImage;<br>&nbsp; &nbsp; procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState; X, Y: Integer);<br>&nbsp; &nbsp; procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; &nbsp; &nbsp; Y: Integer);<br>&nbsp; &nbsp; procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState; X, Y: Integer);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; Draw :Boolean;<br>&nbsp; p1,p2 :TPoint;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; if Button=mbLeft then<br>&nbsp; begin<br>&nbsp; &nbsp; Draw :=True;<br>&nbsp; &nbsp; p1 :=Point(x,y);<br>&nbsp; &nbsp; p2 :=Point(x,y);<br>&nbsp; end;<br>&nbsp; if Button=mbRight then<br>&nbsp; begin<br>&nbsp; &nbsp; Image1.Canvas.MoveTo(p1.x,p1.y);<br>&nbsp; &nbsp; Image1.Canvas.LineTo(p2.x,p2.y);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,<br>&nbsp; Y: Integer);<br>begin<br>&nbsp; if Draw then<br>&nbsp; begin<br>&nbsp; &nbsp; Image1.Canvas.Pen.Mode :=pmNotXor;<br>&nbsp; &nbsp; Image1.Canvas.MoveTo(p1.x,p1.y);<br>&nbsp; &nbsp; Image1.Canvas.LineTo(p2.x,p2.y);<br>&nbsp; &nbsp; p2 :=Point(x,y);<br>&nbsp; &nbsp; Image1.Canvas.MoveTo(p1.x,p1.y);<br>&nbsp; &nbsp; Image1.Canvas.LineTo(p2.x,p2.y);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; if Draw then<br>&nbsp; begin<br>&nbsp; &nbsp; Image1.Canvas.MoveTo(p1.x,p1.y);<br>&nbsp; &nbsp; Image1.Canvas.LineTo(p2.x,p2.y);<br>&nbsp; &nbsp; p2 :=Point(x,y);<br>&nbsp; &nbsp; Image1.Canvas.MoveTo(p1.x,p1.y);<br>&nbsp; &nbsp; Image1.Canvas.LineTo(p2.x,p2.y);<br>&nbsp; &nbsp; Draw :=False;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Draw :=False;<br>end;<br><br>end.<br>
 
接受答案了.
 
后退
顶部