帮我试一下这段代码!图形由四周向中心合拢的!会闪动(50分)

  • 主题发起人 你若有情
  • 开始时间

你若有情

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button4Click(Sender: TObject);
var
newbmp,bkbmp: TBitmap;
i, j, bmpheight, bmpwidth: integer;
Times: integer;
stepx, StepY: Integer;
CenterX, CenterY: Integer;
TmpFileName:String;
begin
TmpFileName:=ExtractFilepath(Application.ExeName)+'file1.bmp';
Self.DoubleBuffered:=true;
Times := 50;
newbmp := TBitmap.Create;
newbmp.loadfromfile(TmpFileName);
bmpheight :=Newbmp.Height;
bmpwidth := Newbmp.Width;
CenterX := round(width / 2);
CenterY := round(height / 2);
stepx := Round(bmpWidth/Times/2);
stepy := round(bmpHeight/Times/2);

for i := 0 to times do
begin
Canvas.FillRect(ClientRect);
Canvas.CopyRect(
Rect(i*stepx,i*stepy,bmpwidth-i*stepx,bmpheight-i*stepy),
newbmp.Canvas,
Rect(i*stepx,i*stepy,bmpwidth-i*stepx,bmpheight-i*stepy));
Application.ProcessMessages;
sleep(100);
end;
newbmp.Free;
end;
 
要防止闪动,应该使用双缓冲机制,最好直接写屏。下面这样不知道行不行!
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message
WM_ERASEBKGND;
...
end;
procedure TBMyComponent.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
// 不要重绘背景
Message.Result := 0
end;
 
我也不想重绘背景,但是不重绘背景前次绘的图还会留在上面!
我想实现图形由四周向中心合拢的效果,有没有其它的方法呢!
 
建议用D7编译一下试试,看看效果。
好像D7自动采用的是双缓冲机制(没有证明)。
我试验了一下,以前的一个程序在D6中会闪烁,经D7编译后运行,感觉不到任何闪烁现象。
 
unit CutPhoto;

interface

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

type
TCutPhotoForm = class(TForm)
StartEffect: TTimer;
Closeimage: TImage;
procedure StartEffectTimer(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
NewBmp: TBitmap;
end;

var
CutPhotoForm: TCutPhotoForm;

implementation
uses
InterfaceForm;

{$R *.dfm}

procedure TCutPhotoForm.StartEffectTimer(Sender: TObject);
var
FullRgn, TranRgn, ImageRgn: THandle;
Margin, X, Y: Integer;
i, times, stepx, stepy: Integer;
begin
StartEffect.Enabled := false; //停止时间

//application.CreateForm(TPhotoForm,PhotoForm);
//PhotoForm.Show;
//PhotoForm.BringToFront;
CutPhotoForm.BringToFront;
times := 25;
stepx := round(CloseImage.width / times / 2);
stepy := round(CloseImage.height / times / 2);
for i := 0 to times do
begin
FullRgn := CreateRectRgn(0, 0, CloseImage.width, CloseImage.Height);
ImageRgn := CreateRectRgn(i * stepx, i * stepy, CloseImage.width - i * stepx, CloseImage.height - i * stepy);
combineRgn(FullRgn, FullRgn, ImageRgn, RGN_And);
SetWindowRgn(Handle, FullRgn, True);
sleep(60);
end;
FullRgn := CreateRectRgn(0, 0, CloseImage.width, CloseImage.Height);
combineRgn(FullRgn, FullRgn, FullRgn, RGN_DIFF);
SetWindowRgn(Handle, FullRgn, true);

end;

procedure TCutPhotoForm.BitBtn1Click(Sender: TObject);
begin
Self.StartEffect.Enabled := true;
end;

end.

慢慢切小!呵呵!看看一下就知道原理是什么了
 
多人接受答案了。
 
顶部