dephi TImage Bug!!!!!!!!!!!!!!!! (0分)

  • 主题发起人 主题发起人 midas
  • 开始时间 开始时间
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.

 
这不是BUG,而是TIMAGE为了保证刷新整个画面,在重画时重写背景。有位朋友曾经
提过,把TImage.Stretch设为True就行了。
 
接受答案了.
 
后退
顶部