[原創]Delphi XE Android/IOS 實現圖片放大縮小的兩種方法


{該文首發於博客園 滔Roy,無須授權即可轉發,請自覺保留頭部申明}

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  更新時間:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM