使用DelphiXE2,我试图识别缩放方向,以将缩放效果应用于图像(TImage),但没有找到这样做的函数,图像的event OnGesture中的EventInfo属性没有此信息。
我已经看到了许多使用Direct2d来放大和缩小的示例,但它使用wp_touch消息直接执行,缩放效果是使用来自直接2d的变换矩阵缩放函数执行的,但我不想使用direct2d来实现这个项目,因为它只有基于触摸的放大和缩小效果,其他事情都是简单的点击。
可以识别输入/输出,存储第一个方向并与当前方向进行比较,因为EventInfo参数有一个属性direction,但我不认为这是一个好方法,否则我错了?
那么在这之后,有什么关于如何在TImage中执行缩放效果的建议或例子吗?我已经这样做了,但它不会在缩放时平移,从而产生每个应用程序都会产生的收缩效果。
发布于 2012-06-14 06:26:14
在阅读了一大堆文档后,我发现正确的方法是:
截取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.X, ZoomCenter.Y);
Invalidate;
//Update with the new values for next interaction
FFirstPoint := FSecondPoint;
FLastDistance := EventInfo.Distance;
end;在WindowsV7.0SDK中有一个用c#编写的示例代码,可以作为参考并帮助我编写lote。
发布于 2017-12-14 22:38:35
对于最新的Delphi版本,EventInfo有一个距离属性。我们不需要计算它。
对于像缩放这样的交互式手势,请查看docwiki中的示例代码:http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/FMXInteractiveGestures_(Delphi)
procedure TForm36.handleZoom(EventInfo: TGestureEventInfo);
var
LObj: IControl;
image: TImage;
begin
LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
if LObj is TImage then
begin
if not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags) then
begin
image := TImage(LObj.GetObject);
image.Width := image.Width + (EventInfo.Distance - FLastDIstance)/2;
image.Height := image.Height + (EventInfo.Distance - FLastDIstance)/2;
image.Position.X := image.Position.X - (EventInfo.Distance - FLastDIstance)/2;
image.Position.Y := image.Position.Y - (EventInfo.Distance - FLastDIstance)/2;
end;
end;
FLastDIstance := EventInfo.Distance;
end;https://stackoverflow.com/questions/10986710
复制相似问题