为什么图象会闪烁(200分)

  • 主题发起人 主题发起人 achang
  • 开始时间 开始时间
A

achang

Unregistered / Unconfirmed
GUEST, unregistred user!
unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
foreimage: TImage;
backimage: TImage;
procedure FormCreate(Sender: TObject);
//Procedure CopyRect(const Dest: TRect; Canvas: TCanvas; const Source: Trect);
procedure ImageCopy(BoxCenterX, BoxCenterY, BoxSide: Integer);
procedure foreimageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
const

sSide=30;

dSide=45;

var

msHide: Boolean;

OldX, OldY, NewX, NewY: Integer;

DestRect, SourceRect : TRect;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
msHide:=True;

Canvas.CopyMode:=cmSrcCopy;

end;


procedure TForm1.ImageCopy(BoxCenterX, BoxCenterY, BoxSide: Integer);

begin

with SourceRect do

begin

Left:=BoxCenterX-BoxSide;

Top:=BoxCenterY-BoxSide;

Right:=BoxCenterX+BoxSide;

Bottom:=BoxCenterY+BoxSide;

end;

with DestRect do

begin

Left:=BoxCenterX-dSide;

Top:=BoxCenterY-dSide;

Right:=BoxCenterX+dSide;

Bottom:=BoxCenterY+dSide;

end;

ForeImage.Canvas.CopyRect(DestRect, BackImage.Canvas, SourceRect);

end;




procedure TForm1.foreimageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
NewX:=X;

NewY:=Y;

if msHide then

begin

OldX:=NewX;

OldY:=NewY;

msHide:=False;

ShowCursor(False);

end else

begin

ImageCopy(OldX, OldY, dSide);

end;

ImageCopy(NewX, NewY, sSide);

OldX:=NewX;

OldY:=NewY;


end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not msHide then

begin

msHide:=True;

ShowCursor(True);

ImageCopy(OldX, OldY, dSide);

end;



end;

end.
 
我的一个练习,一边从 ImageList 中读出图形,显示到 Image 中,一边让 Image 在 Form 上由左到右移动。
 
这个放大镜如果要不闪烁则应该Form.doublebuffered:=true;
我试过代码,效果很好!其他的不用改!
procedure TForm1.FormCreate(Sender: TObject);
begin
msHide:=True;

Canvas.CopyMode:=cmSrcCopy;
self.DoubleBuffered:=true;

end;
 
用这句吧,在窗体onshow事件中加入
form1.doublebuffer:=true;
 
当你对象很多的时候闪烁更厉害,建议把你的IMAGE放在一个TPANEL上,然后TPANEL的大小设置和IMAGE一样大或者autosize也行,基本上可以满足你的要求。
 

Similar threads

后退
顶部