📄 pathtoregionu.pas
字号:
unit PathToRegionU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TextRgn: HRGN; // holds the text region
YVel: Integer; // the region's vertical velocity
TempBitmap: TBitmap; // an offscreen bitmap used to eliminate flicker
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
{begin the a path bracket for the form's device context}
BeginPath(Canvas.Handle);
{set the background mode to transparent. this is necessary so that the path
will consist of the area inside of the text. without this, the path is
defined as the area outside of the text}
SetBkMode(Canvas.Handle, TRANSPARENT);
{Output a word to the form. this is captured as part of the path. note that
the form's font is set to size 48 Arial}
TextOut(Canvas.Handle, 1, 1, 'DELPHI', Length('DELPHI'));
{end the path bracket}
EndPath(Canvas.Handle);
{convert the path into a region. note that this discards the path in the
device context}
TextRgn := PathToRegion(Canvas.Handle);
{create the offscreen bitmap and initialize it to the size of the
invisible TImage}
TempBitmap := TBitmap.Create;
TempBitmap.Width := Image1.Width;
TempBitmap.Height := Image1.Height;
{initialize the vertical velocity}
YVel := 1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
RegionBounds: TRect; // holds the bounding rectangle of the region
begin
{retrieve the bounding rectangle of the region}
GetRgnBox(TextRgn, RegionBounds);
{if the region is at the top or bottom edge of the form, reverse its velocity}
if (RegionBounds.Top<0) or (RegionBounds.Top>ClientRect.Bottom-
(RegionBounds.Bottom-RegionBounds.Top)) then
YVel := 0-YVel;
{offset the region vertically by its velocity}
OffsetRgn(TextRgn, 0, YVel);
{draw the graphic in the invisible TImage to the offscreen bitmap}
TempBitmap.Canvas.Draw(0, 0, Image1.Picture.Bitmap);
{invert the area inside of the text region}
InvertRgn(TempBitmap.Canvas.Handle, TextRgn);
{copy the offscreen bitmap to the form, eliminating flicker}
Canvas.Draw(0, 0, TempBitmap);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{the region is no longer needed, so destroy it}
DeleteObject(TextRgn);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -