gpt4 book ai didi

delphi - 如何使用手势识别缩放方向(进/出)并应用缩放效果?

转载 作者:行者123 更新时间:2023-12-03 15:33:14 31 4
gpt4 key购买 nike

使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息.

我见过很多使用 Direct2d 来放大和缩小的示例,但它直接使用 wp_touch 消息来执行此操作,并且缩放效果是使用 direct 2d 中的变换矩阵缩放函数来执行的,但我不想使用 direct2d对于这个项目,因为它只会有基于触摸的放大和缩小效果,其他的都是简单的点击。

可以识别存储第一个方向的输入/输出并与当前方向进行比较,因为 EventInfo 参数具有属性 Direction,但我认为这不是一个很好的方法,还是我错了?

那么在那之后有关于如何在 TImage 中执行缩放效果的任何建议或示例吗?我已经这样做了,但在缩放时它不会平移以提供每个应用程序都会产生的捏合效果。

最佳答案

阅读了大量文档后,我发现正确的做法是:

拦截EventInfo.GestureID来识别我的例子中所需的命令,即缩放命令,之后您应该读取EventInfo.Flags并识别它是否是gfBegin,以便您可以缓存第一个位置点(x,y)和第一个距离,当标志不同时,gfBegin 使用第一个点和当前点 (EventInfo.Location) 执行计算

基本命令应该是这样的:

 case EventInfo.GestureID of
igiZoom:
begin
if (EventInfo.Flags = [gfBegin]) then
begin
FLastDistance := EventInfo.Distance;
FFirstPoint.X := EventInfo.Location.X;
FFirstPoint.Y := EventInfo.Location.Y;
FFirstPoint := ScreenToClient(FFirstPoint);

if (FSecondPoint.X = 0) and (FSecondPoint.Y = 0) then
begin
FSecondPoint.X := EventInfo.Location.X + 10;
FSecondPoint.Y := EventInfo.Location.Y + 10;
FSecondPoint := ScreenToClient(FSecondPoint);
end;
//ZoomCenter is a local TPoint var
ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2),
((FFirstPoint.Y + FSecondPoint.Y) div 2));
//Apply the zoom to the object
FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y);

Invalidate;
end
else
begin
FSecondPoint.X := EventInfo.Location.X;
FSecondPoint.Y := EventInfo.Location.Y;
FSecondPoint := ScreenToClient(FSecondPoint);

ZoomCenter.Create(((FFirstPoint.X + FSecondPoint.X) div 2),
((FFirstPoint.Y + FSecondPoint.Y) div 2));

FDrawingObject.Zoom(EventInfo.Distance / FLastDistance, ZoomCenter.X, ZoomCenter.Y);

Invalidate;
//Update with the new values for next interaction
FFirstPoint := FSecondPoint;
FLastDistance := EventInfo.Distance;
end;

Windows v7.0 SDK 中有一个用 C# 编写的示例代码,可以作为引用,对我有很大帮助。

关于delphi - 如何使用手势识别缩放方向(进/出)并应用缩放效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986710/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com