delphi Image 32 动画演示1
Image 32 自带的Demo,添加一些注解。
unit uFrmAnimation;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
System.Variants, System.Math, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, //
Img32, Img32.Layers;
type
TfrmAnimation = class(TForm)
Panel1: TPanel;
btnDec: TButton;
btnAdd: TButton;
lblSpeed: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnDecClick(Sender: TObject);
private
timer: TTimer; // 定时器,刷新动画
reversing: Boolean; // 颠倒
imgIndex: integer; // 动画图片索引
layeredImage: TLayeredImage32; // 图片分层对象 Image32 (对象存储)
drawRec: TRect;
procedure Timer1Timer(Sender: TObject);
protected
procedure WMERASEBKGND(var message: TMessage); message WM_ERASEBKGND;
public
end;
var
frmAnimation: TfrmAnimation;
implementation
{$R *.dfm}
uses
Img32.Draw, Img32.Vector, Img32.Extra;
{ TfrmAnimation }
procedure TfrmAnimation.btnAddClick(Sender: TObject);
begin
timer.Interval := Max(1, timer.Interval div 2);
end;
procedure TfrmAnimation.btnDecClick(Sender: TObject);
begin
timer.Interval := Max(1, timer.Interval * 2);
end;
procedure TfrmAnimation.FormCreate(Sender: TObject);
var
i, j, ballsize, SpaceAbove, maxSquishSize: integer;
img: TImage32;
path: TPathD;
ballRec: TRect;
begin
ballsize := DPIAware(100); // 球大小, 根据屏幕分辨率缩放“值”(即屏幕像素/英寸或“点/英寸”)。(请参阅Windows操作系统设置|系统|显示|缩放和布局。)提供了一种实现图像和控件大小一致的�
SpaceAbove := ballsize * 2; // 上方空间大小
drawRec := Img32.Vector.Rect(0, 0, ballsize, ballsize + SpaceAbove); // 绘制区域 (0,0,100,300)
layeredImage := TLayeredImage32.Create;
layeredImage.SetSize(ballsize, ballsize + SpaceAbove); // 与绘制区域大小相同
layeredImage.BackgroundColor := Color32(self.Color); // clBtnFace);
// path: for drawing a black line at the bottom of the image
path := Img32.Vector.MakePath([0, ballsize * 3 - 8, ballsize, ballsize * 3 - 8]); // 下方的线条
with layeredImage.AddLayer(TLayer32) do // 添加一个层图形对象
begin
SetInnerBounds(RectD(drawRec)); // 设置绑定区域
DrawLine(Image, path, 5, clBlack32, esSquare); // Img32.Draw.DrawLine 画线 5为线宽
end;
ballRec := Img32.Vector.Rect(0, 0, ballsize, ballsize); // 球的区域
Winapi.Windows.InflateRect(ballRec, -15, -15); // 扩展区域(负数为缩小)
path := Ellipse(ballRec); // Img32.Vector.Ellipse //㮋圆(长宽相等为圆)
// 31 images (25 + 6) will be added to masterImageList. Each will be viewed 31个图像(25+6)将被添加到masterImageList。每个都将被查看
// twice in each loop except for the top and bottom images. (60 frames/loop) 除了顶部和底部图像之外,每个循环中两次。(60帧/循环)
img := TImage32.Create(ballsize, ballsize);
try
// draw the ball
DrawPolygon(img, path, frNonZero, clLime32); // 绘制多边形(填充)
Draw3D(img, path, frNonZero, 8, 8); // 使填充区域具有3D效果
DrawLine(img, path, 3, clGreen32, esPolygon); // 绘制线(此外为圆的边框)
// 以下是直接(球无变形,只是位置变化)
for i := 1 to 25 do
begin
with layeredImage.AddLayer(TLayer32) do
begin
SetInnerBounds(RectD(drawRec));
j := Round(power(SpaceAbove, i / 25));
ballRec := Img32.Vector.Rect(0, j, ballsize, j + ballsize);
Image.CopyBlend(img, img.Bounds, ballRec); // 源 完整拷贝到 目标位置
Visible := false; // 默认此层都是隐藏的.
end;
end;
// 以下是直接(球有变形,目标区域高度变小)
maxSquishSize := Round(ballsize * 0.75);
for i := 1 to 6 do
with layeredImage.AddLayer(TLayer32) do
begin
SetInnerBounds(RectD(drawRec));
ballRec := Img32.Vector.Rect(0, SpaceAbove + maxSquishSize - Round(power(maxSquishSize, (6 - i) / 6)), ballsize, SpaceAbove + ballsize);
Image.CopyBlend(img, img.Bounds, ballRec);
Visible := false; // 默认此层都是隐藏的.
end;
finally
img.Free;
end;
// 创建,启动定时器
timer := TTimer.Create(self);
timer.OnTimer := Timer1Timer;
timer.Interval := 15;
timer.Enabled := true;
end;
procedure TfrmAnimation.FormDestroy(Sender: TObject);
begin
layeredImage.Free;
timer.Free;
end;
procedure TfrmAnimation.FormPaint(Sender: TObject);
begin
with layeredImage.GetMergedImage do //获取合并的图像(只有图层显示状态的才参与合并)
CopyToDc(Bounds, Canvas.Handle, drawRec.Left, drawRec.Top, false);
end;
procedure TfrmAnimation.FormResize(Sender: TObject);
begin //当窗口大小发生变化时,要重新计算绘制区域位置
if csDestroying in ComponentState then
Exit;
// repaint the whole background only when resizing. 只有在调整大小时才能重新绘制整个背景。
Canvas.FillRect(ClientRect);
// center the animation in the form clientrect 将动画置于窗口显示区域的中心
Img32.Vector.TranslateRect(drawRec, // 修改 drawRec
-drawRec.Left + (ClientWidth - layeredImage.Width) div 2, //
-drawRec.Top + (ClientHeight - layeredImage.Height) div 2); //
end;
procedure TfrmAnimation.Timer1Timer(Sender: TObject);
begin
if imgIndex > 0 then //当前绘制的图层索引
layeredImage[imgIndex].Visible := false; //此层不显示
// 计算当前应该显示哪张图片
if reversing then //是否颠倒
begin
dec(imgIndex);
if (imgIndex = 1) then
reversing := false;
end
else
begin
inc(imgIndex);
if (imgIndex = layeredImage.Count - 1) then
reversing := true;
end;
layeredImage[imgIndex].Visible := true; //当前层显示
Invalidate; //使窗口无效(即要求重新绘制窗口)
end;
procedure TfrmAnimation.WMERASEBKGND(var message: TMessage);
begin
message.Result := 1;
// this stops windows unhelpfully erasing the form's canvas. 这将阻止windows毫无帮助地擦除窗体的画布。
// We want full control of painting (see FormPaint below). 我们希望完全控制绘画(请参阅下面的FormPaint)
end;
end.
效果:
欢迎微信搜一搜 IT软件部落 关注公众号,你可以了解更详细的内容
欢儿微信扫码关注 IT软件部落 公众号,你可以了解更详细的内容
delphi Image 32 动画演示1的更多相关文章
- 【动画】JQuery实现冒泡排序算法动画演示
1 前言 冒泡排序是大家最熟悉的算法,也是最简单的排序算法,因其排序过程很象气泡逐渐向上漂浮而得名.为了更好的理解其基本的思想,毛三胖利用JQuery实现了冒泡排序的动画演示,并计划陆续实现其它排序算 ...
- Visaul Studio 常用快捷键的动画演示
从本篇文章开始,我将会陆续介绍提高 VS 开发效率的文章,欢迎大家补充~ 在进行代码开发的时候,我们往往会频繁的使用键盘.鼠标进行协作,但是切换使用两种工具会影响到我们的开发速度,如果所有的操作都可以 ...
- 免费的精品: Productivity Power Tools 动画演示
Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率.它的出现一定程度上弥补和完善了 Visual Studio 自身的不足, ...
- Productivity Power Tools 动画演示(转)
Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率.它的出现一定程度上弥补和完善了 Visual Studio 自身的不足, ...
- 【转载】Visaul Studio 常用快捷键的动画演示
在进行代码开发的时候,我们往往会频繁的使用键盘.鼠标进行协作,但是切换使用两种工具会影响到我们的开发速度,如果所有的操作都可以只用键盘来完成,那开发效率将得到大幅度的提升.因此,灵活地应用 Visua ...
- Productivity Power Tools 动画演示--给力的插件工具
免费的精品: Productivity Power Tools 动画演示 Productivity Power Tools 是微软官方推出的 Visual Studio 扩展,被用以提高开发人员生产率 ...
- delphi 2010是动画GIF的支持方法
下面delphi 2010是动画GIF的支持方法: 1.在窗体上放一个Image1控件.注意:这时设置其Picture属性,加载一幅动画GIF是不会动画显示的. 2.在窗体的FormCreate事 ...
- jQuery each、节点操作、动画演示、尺寸操作、扩展方法
一.each 1.方式一:$.each(数组或者自定义对象,function(i,j){console.log(i,j)}) $.each(li,function(i,j){ console.log( ...
- 如何用 Keynote 制作动画演示(转)
原文:如何用 Keynote 制作动画演示 Keynote 里的很多特效可以用来制作效果不错的演示,一页页的将需要演示的内容交代清楚后,直接输出成 m4v 的视频格式,为了方便贴到博客或者发布到 Tw ...
- DELPHI纤程的演示
DELPHI纤程的演示 DELPHI7编译运行通过. 纤程实现单元: unit FiberFun; //Fiber(纤程测试Demo)//2018/04/11//QQ: 287413288 //参考 ...
随机推荐
- 2024-08-24:用go语言,给定一个下标从1开始,包含不同整数的数组 nums,数组长度为 n。 你需要按照以下规则进行 n 次操作,将数组 nums 中的所有元素分配到两个新数组 arr1 和
2024-08-24:用go语言,给定一个下标从1开始,包含不同整数的数组 nums,数组长度为 n. 你需要按照以下规则进行 n 次操作,将数组 nums 中的所有元素分配到两个新数组 arr1 和 ...
- Go channel 介绍
Go 语言(Golang)中的 chan 是通道(channel)的缩写,用于在不同的 goroutine 之间进行通信.通道允许你在 goroutine 之间传递数据,从而实现同步和共享内存.下面是 ...
- 关于java连接数据库时提示异常java.sql.SQLException: No suitable driver found for说明
当我们测试一个新的数据库服务时,需要使用对方提供jdbc驱动来连接数据库,有时候简单的写个demo去连接,发现提示异常: java.sql.SQLException: No suitable driv ...
- 全网最适合入门的面向对象编程教程:42 Python常用复合数据类型-collections容器数据类型
全网最适合入门的面向对象编程教程:42 Python 常用复合数据类型-collections 容器数据类型 摘要: 在 Python 中,collections 模块提供了一组高效.功能强大的容器数 ...
- windows docker(25.0.3) 运行 1.4.1 nacos 容器
Docker Desktop 设定图标 -> Docker Engine 设定国内镜像源 添加配置: { "builder": { "gc": { &qu ...
- Jenkins 运行pipeline 报错:A Jenkins administrator will need to approve this script before it can be us
之前没有注意过这个问题,是因为之前运行pipeline时,默认勾选了"使用 Groovy 沙盒" 这次不小心取消了勾选导致,重新加上勾选即可
- IEEE754浮点数表示形式
IEEE754浮点数表示形式 IEEE754浮点数官方文档:https://ieeexplore.ieee.org/document/8766229 浮点数的上述表示形式,既没有规定阶码和尾数的位数, ...
- ZEGO 教程 | RTC + AI 视觉的最佳实践(移动端)
摘要:帮助开发者在音视频场景中快速获得 AI 视觉功能 -- 美颜.滤镜.背景抠图等. 文|即构 Native SDK 开发团队 Z世代作为社会新的消费主力,追求个性.热爱新奇事物,青睐与酷炫 ...
- Filter——过滤器
Filter Filter 快速入门 Filter 执行流程 1.放行前,对 request 数据进行处理 2.放行后,对 response 数据进行处理 ...
- HTML——基础标签
基础标签 图片.音频.视频标签 src:资源路径 1.绝对路径 2.相对路径 ./ 表示本级目录 (可以省略) ../ 表示上级目录 超链接标签 列表标签 表格标签 ...