📄 cooleffectu.pas
字号:
unit CoolEffectU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure DrawEffect;
public
{ Public declarations }
end;
var
Form1: TForm1;
Offset: Integer; // bitmap offset counter
Buffer, TileBitmap: TBitmap; // offscreen and texture bitmaps
implementation
{$R *.DFM}
procedure TForm1.FormPaint(Sender: TObject);
begin
{draw a frame of the effect}
DrawEffect;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{initialize the offset counter}
Offset := 0;
{create an offscreen buffer the size of the form's client area}
Buffer := TBitmap.Create;
Buffer.Width := ClientWidth;
Buffer.Height := ClientHeight;
{create and load the texture bitmap used in the letters}
TileBitmap := TBitmap.Create;
TileBitmap.LoadFromFile(ExtractFilePath(ParamStr(0))+'Tile.bmp');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{free the offscreen and texture bitmaps}
Buffer.Free;
TileBitmap.Free;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
{increment the offset counter}
Inc(Offset);
{if the offset is larger than the texture bitmap (64 pixels), reset it}
if Offset>63 then
Offset := 0;
{draw a frame of the effect}
DrawEffect;
end;
procedure TForm1.DrawEffect;
var
iCount: Integer; // a general loop counter
ClipRgn: HRGN; // holds the region
begin
{begin a path bracket}
BeginPath(Canvas.Handle);
{output some text, defining the path as the interior of the text}
SetBkMode(Canvas.Handle, TRANSPARENT);
TextOut(Canvas.Handle, 10, 60, 'DELPHI', 6);
{end the path bracket}
EndPath(Canvas.Handle);
{convert the path into a region, and select this region as the offscreen
buffer's clipping region}
ClipRgn := PathToRegion(Canvas.Handle);
SelectClipRgn(Buffer.Canvas.Handle, ClipRgn);
{draw the texture bitmap into the area defined by the region. it will get
clipped to the interior of the letters}
for iCount := 0 to 4 do
Buffer.Canvas.Draw(iCount*64-Offset, 60, TileBitmap);
{delete the clipping region of the offscreen buffer}
SelectClipRgn(Buffer.Canvas.Handle, 0);
{reset the clipping region of the offscreen buffer, this time defining the
clipping region as the area outside of the letters}
ExtSelectClipRgn(Buffer.Canvas.Handle, ClipRgn, RGN_DIFF);
{draw the image of the Earth onto the offscreen buffer. the previously drawn
letters will not be obscured by the bitmap, as they are protected by the
current clipping region}
Buffer.Canvas.Draw(0, 0, Image1.Picture.Bitmap);
{draw the offscreen buffer to the form. this eliminates flicker and is an
animation technique known as double buffering}
Canvas.Draw(0, 0, Buffer);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -