Delphi XE Android/IOS 实现图片放大缩小的两种方法


本文整理自网络,侵删。

 

1、TImage

var
  LObj: IControl;
  LImage: TImage;
  LImageCenter: TPointF;
begin
  if EventInfo.GestureID = igiZoom then
  begin
    LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
    if LObj is TImage then
    begin
      if (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags)) and
        (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags)) then
      begin
        { zoom the image }
        LImage := TImage(LObj.GetObject);
        LImageCenter := LImage.Position.Point + PointF(LImage.Width / 2,
          LImage.Height / 2);
        LImage.Width := LImage.Width + (EventInfo.Distance - FLastDistance);
        LImage.Height := LImage.Height + (EventInfo.Distance - FLastDistance);
        LImage.Position.X := LImageCenter.X - LImage.Width / 2;
        LImage.Position.Y := LImageCenter.Y - LImage.Height / 2;
      end;
      FLastDistance := EventInfo.Distance;
    end;
  end;
 

2、TImageViewer


procedure TForm1.ImageViewer1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
  case EventInfo.GestureID of
    igiZoom:
    begin
      if (EventInfo.Distance - fDistance)/2 > 0 then ImageViewer1.BitmapScale:=ImageViewer1.BitmapScale + 0.01  else
      if (EventInfo.Distance - fDistance)/2 < 0 then ImageViewer1.BitmapScale:=ImageViewer1.BitmapScale - 0.01;
      fDistance:=EventInfo.Distance;
      Handled:=True;
    end;
  end;
end;
  

 

创建时间:2020.06.26  更新时间:

 

博客园 滔Roy https://www.cnblogs.com/guorongtao

相关阅读 >>

Delphi 不重复运行外部程序exe

Delphi 获取本机 hostname ip address

Delphi 生成全球唯一标识符

idhttp控件的防止异常的处理

Delphi xe5 android 设置权限

Delphi 我的电脑连接到 internet 了吗?

Delphi idhttp post 提交 json

Delphi图像处理 -- 图像卷积

Delphi中输入框不能输入初数字意外的字符串的函数(isnumeric)

Delphi 附加数据读取

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...