M
midas
Unregistered / Unconfirmed
GUEST, unregistred user!
用下面的程序画线时,image不停的闪烁
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
px,py: integer;
oldX, oldY : integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (px = 0) and (Py=0) then
begin
px := x;py:=y;
exit;
end;
Image1.Canvas.Pen.Mode := pmCopy ;
Image1.Canvas.MoveTo(px,py);
Image1.Canvas.LineTo(x,y);
px := x; py := y;
oldX := x; oldY := y;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (px <> 0) then
begin
Image1.Canvas.Lock;
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Pen.Mode := pmXor;
Image1.Picture.Bitmap.Canvas.MoveTo(px,py);
Image1.Picture.Bitmap.Canvas.Lineto(oldx,oldy);
Image1.Picture.Bitmap.Canvas.MoveTo(px,py);
Image1.Picture.Bitmap.Canvas.Lineto(x,y);
oldx := x; oldY := y;
Image1.Canvas.Unlock;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
px,py: integer;
oldX, oldY : integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (px = 0) and (Py=0) then
begin
px := x;py:=y;
exit;
end;
Image1.Canvas.Pen.Mode := pmCopy ;
Image1.Canvas.MoveTo(px,py);
Image1.Canvas.LineTo(x,y);
px := x; py := y;
oldX := x; oldY := y;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (px <> 0) then
begin
Image1.Canvas.Lock;
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Pen.Mode := pmXor;
Image1.Picture.Bitmap.Canvas.MoveTo(px,py);
Image1.Picture.Bitmap.Canvas.Lineto(oldx,oldy);
Image1.Picture.Bitmap.Canvas.MoveTo(px,py);
Image1.Picture.Bitmap.Canvas.Lineto(x,y);
oldx := x; oldY := y;
Image1.Canvas.Unlock;
end;
end;
end.