delphi Image32 动画演示2
Image 32 自带的Demo,添加一些注解。
unit uFrmAnimation2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ExtCtrls, System.Math, Img32;
type
TfrmAnimation2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
img: TImage32;
imgCnt: Integer;
timer: TTimer;
imgIndex: Integer;
drawRec: TRect;
procedure Timer1Timer(Sender: TObject);
protected
procedure WMERASEBKGND(var message: TMessage); message WM_ERASEBKGND;
end;
var
frmAnimation2: TfrmAnimation2;
implementation
{$R *.dfm}
{$R images.res} // 这里有图片资源
uses
Img32.Extra, Img32.Vector, Img32.Fmt.PNG;
function GetMinRotationRect(const rec: TRect): TRect;
var
mp: TPointD;
radius: double;
begin // 得出图片以中心点旋转时,所有旋转画布可正常展示的矩形区域.
mp.X := rec.Width / 2;
mp.Y := rec.Height / 2;
radius := Distance(PointD(rec.Left, rec.Top), mp); // Img32.Vector 2点之间的距离
Result.Left := Ceil(mp.X - radius);
Result.Right := Ceil(mp.X + radius);
Result.Top := Ceil(mp.Y - radius);
Result.Bottom := Ceil(mp.Y + radius);
end;
// ------------------------------------------------------------------------------
function EnumResNameProc(hModule: hModule; lpszType, lpszName: PChar; lParam: LONG_PTR): BOOL; stdcall;
begin
inc(PInteger(lParam)^);
Result := true;
end;
procedure TfrmAnimation2.FormCreate(Sender: TObject);
var
i: Integer;
angle, angleDelta: double;
begin
img := TImage32.Create;
// 此窗口做为独立程序时,可以这样修改窗口大小,对此综合实例,暂无用途
// img.LoadFromResource('RAZZ_00', 'PNG');
// with GetMinRotationRect(img.Bounds) do
// begin
// ClientWidth := Width;
// ClientHeight := Height;
// end;
// 统计在资源中为 PNG类型资源的数量
EnumResourceNames(0, 'PNG', @EnumResNameProc, LONG_PTR(@imgCnt));
// 设置窗体透明.
self.Color := clRed;
self.TransparentColorValue := self.Color;
self.TransparentColor := true;
// make the form **background** transparent
// Self.TransparentColor := true; // :))
// and make sure BorderStyle = bsNone and BorderIcons = []
// 创建定时器,定时要求界面刷新
timer := TTimer.Create(self);
timer.OnTimer := Timer1Timer;
timer.Interval := 33;
end;
procedure TfrmAnimation2.FormDestroy(Sender: TObject);
begin
img.Free;
timer.Free;
end;
procedure TfrmAnimation2.FormKeyPress(Sender: TObject; var Key: Char);
begin
// if CharInSet(Key, [#13, #27, #32]) then
// Close;
end;
procedure TfrmAnimation2.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
timer.Enabled := not timer.Enabled;
end;
procedure TfrmAnimation2.FormPaint(Sender: TObject);
var
X, Y: Integer;
mpForm: TPointD;
begin
with ClientRect do
mpForm := PointD(Width / 2, Height / 2);
img.LoadFromResource(format('RAZZ_%2.2d', [imgIndex]), 'PNG');
X := Round(mpForm.X - img.MidPoint.X);
Y := Round(mpForm.Y - img.MidPoint.Y);
//居中中显示
Canvas.FillRect(ClientRect);
img.CopyToDc(img.Bounds, Canvas.Handle, X, Y, false);
end;
procedure TfrmAnimation2.Timer1Timer(Sender: TObject);
begin
imgIndex := (imgIndex + 1) mod imgCnt; //下1张图.
Invalidate;
end;
procedure TfrmAnimation2.WMERASEBKGND(var message: TMessage);
begin
message.Result := 1;
end;
end.
欢迎微信搜一搜 IT软件部落 关注公众号,你可以了解更详细的内容
欢儿微信扫码关注 IT软件部落 公众号,你可以了解更详细的内容
posted on 2024-06-11 16:39 bluejade2024 阅读(44) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具