delphi – 如何使用手势识别缩放方向(输入/输出)并应用缩放效果
使用Delphi XE 2我试图识别缩放方向以将缩放效果应用于图像(T
Image),但没有找到执行此功能的函数,并且在Image的OnGesture事件中的EventInfo属性没有此信息.
我已经看到使用Direct2d进行放大和缩小的样本,但它直接使用wp_touch消息来执行此操作,并使用直接2d的变换矩阵比例函数执行缩放效果,但我不想将direct2d用于此项目因为它只有基于触摸的放大和缩小效果,其他的是简单的点击. 有可能识别存储第一个方向的输入/输出并与当前方向进行比较,因为EventInfo参数具有属性Direction但我认为这不是很好的方法,或者我错了? 那么之后是否有关于如何在TImage中执行缩放效果的任何推荐或示例?我已经做到了,但是在缩放时不会平息每个应用程序的效果. 解决方法
在阅读了一些文件后,我发现正确的方法是:
拦截EventInfo.GestureID以识别我的缩放命令所需的命令,之后您应该读取EventInfo.Flags并确定它是否是gfBegin,以便您可以缓存第一个位置点(x,y)和第一个距离,当标志不同时,gfBegin使用firstpoint和currentpoint(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.Y); Invalidate; //Update with the new values for next interaction FFirstPoint := FSecondPoint; FLastDistance := EventInfo.Distance; end; Windows v7.0 SDK中提供了一个c#中的示例代码,可用作参考并帮助我做一些操作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |