W
westbird
Unregistered / Unconfirmed
GUEST, unregistred user!
谁能帮我看看这个程序---消除图象闪烁
这是一个例子程序
我用的是Delphi6,panel.align:=alclient;
image.transparent:=false;
怎样消除图象闪烁
原程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
FramePanel: TPanel;
BackImage: TImage;
ForeImage: TImage;
procedure FormCreate(Sender: TObject);
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
{$R *.dfm}
const
sSide=30;
dSide=45;
var
msHide: Boolean;
OldX, OldY, NewX, NewY: Integer;
DestRect, SourceRect : TRect;
//其中,常量sSide和dSide用以控制"放大镜"的大小和放大倍数;变量msHide控制光标(鼠标)的隐藏和打开;其它变量用以确定放大部位。
procedure 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;
form1.ForeImage.Canvas.CopyRect(DestRect, form1.BackImage.Canvas, SourceRect);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.DoubleBuffered:=true;
msHide:=True;
Canvas.CopyMode:=cmSrcCopy;
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.
这是一个例子程序
我用的是Delphi6,panel.align:=alclient;
image.transparent:=false;
怎样消除图象闪烁
原程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
FramePanel: TPanel;
BackImage: TImage;
ForeImage: TImage;
procedure FormCreate(Sender: TObject);
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
{$R *.dfm}
const
sSide=30;
dSide=45;
var
msHide: Boolean;
OldX, OldY, NewX, NewY: Integer;
DestRect, SourceRect : TRect;
//其中,常量sSide和dSide用以控制"放大镜"的大小和放大倍数;变量msHide控制光标(鼠标)的隐藏和打开;其它变量用以确定放大部位。
procedure 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;
form1.ForeImage.Canvas.CopyRect(DestRect, form1.BackImage.Canvas, SourceRect);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.DoubleBuffered:=true;
msHide:=True;
Canvas.CopyMode:=cmSrcCopy;
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.