delphi 预览图片2 (MouseUP)

时间:2023-03-09 16:46:24
delphi 预览图片2 (MouseUP)

这个是自己项目在使用的,所以带有些业务功能的代码。

逻辑上使用的大多是 mouseup ,MouseMove,Mousedown。使用recttangle容器实现滑动。网上有这个下载demo。

另外移动端要注意线程的异步同步的控制。

delphi 预览图片2 (MouseUP)

unit UShowPictureZoomIn;

interface

uses
  System.SysUtils,
  System.Types,
  System.UITypes,
  System.IOUtils,
  System.Classes,
  System.Variants,
  System.Messaging ,
  System.Generics.Collections,
  FMX.Types,
  FMX.Graphics,
  FMX.Controls,
  FMX.Forms,
  FMX.Dialogs,
  FMX.StdCtrls,
  FMX.Objects,
  FMX.Effects,
  FMX.Ani,
  FMX.Controls.Presentation,
  FMX.Layouts,DRCommonEvent,
  DRFormClass,PublicVariables,ParentFrm,UDM,MSFileCLass,
  GetData,Common,Datasnap.DBClient,DataRec,CDSHelper ,
  {$IFNDEF MSWINDOWS}
  FMX.Gestures,
  {$ENDIF}
  FMX.Edit;

type
  //  TArray   =  array of string;
  TArrays  =  array of array of string;
  TFrmShowPictureZoomIn = class(TParentform)
    LayoutContainer: TLayout;
    Image1: TImage;
    Image2: TImage;
    RectBottom: TRectangle;
    AChkType: TCheckBox;
    lblSelectOK: TLabel;
    RectTop: TRectangle;
    ImgReturn: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    //
    procedure RectOnMouseDown(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Single);
    procedure RectOnMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Single);
    procedure RectOnMouseUP(Sender: TObject; Button: TMouseButton;Shift : TShiftState; X, Y: Single);
    procedure FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo;
      var Handled: Boolean);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure lblSelectOKClick(Sender: TObject);
    procedure ImgReturnClick(Sender: TObject);
    procedure FormTap(Sender: TObject; const Point: TPointF);
    procedure RectTopClick(Sender: TObject);
  private
    { Private declarations }
     {$IFNDEF MSWINDOWS}
     GestureManager1  : TGestureManager ;
     {$ENDIF}
     ARectOK         : TRectangle;
     ARectCancel     : TRectangle ;
     ARectChk        : TRectangle ;
     ARectIsCreate   : boolean ;
     AImage          : Array of TImage ;
     ARect           : Array of TRectangle ;
    //
     FLastPosition   : TPointF;
     FLastDIstance   : integer ;
     FOriginalWidth  : Array of Single ;
     FOriginalHeight : Array of Single ;
     FOriginalX      : Array of single ;
     FOriginalY      : Array of Single ;
     FZoomWidth      : Single ;
     FZoomHeight     : Single ;
    //
    BMSCarrierObject_ID:string;
   // AImgGuIDRelationship:TImgGuIDRelationship;
    ArrayOfGuID    :TArrays;
    firstHit  :  integer;
    AGuIDlist:Tstringlist;
   // ArrayOfGuID    :array of array of string;

FBitmapList    : TList<TBitmap>;

FImgListPath   : TList<string>;
    FCurrentIndex  : integer ;
    PageCount,PageCountA      : integer ;
    pageIndex      : Integer;
    tapDownPos     : TPointF;
    tapDownPosF    : TPointF;
    FX             : single ;

tapIsDown: Boolean;  // This is needed, since the tap can happend outside control and then moved inside it to release
    procedure  ScrollMainView(page: Integer);
    procedure  InitFormInfo ;
    //
    procedure  InitImageList();
    procedure  InitCurrentImage ;
    procedure  InitFormInfoA ;
    //
    procedure  InitImageListPath ;
    procedure  InitCurrentImgPath ;
    //
    procedure  InitImageStrPath ;
    Procedure  InitCurrentPath ;

procedure  ARectCancelOnClick(Sender :TObject);
    procedure  ARectOnClick(Sender :TObject);
    procedure  LblOkClick(Sender: TObject);

procedure  LoadImgGuIDInfo;   //下载小图guid和大图guid对应表    暂时不用
    procedure  LoadZoomImg(AIndex:integer);
  public
    { Public declarations }
    //缩约图list,缩约图idlist,点击的第几张图,载体id,缩约图和原图对应的id 2维表
    class Procedure  ShowForm(AList:TList<TBitmap>;BGuIDlist:Tstringlist;AIndex
                      :integer;AMSCarrierObject_ID:string; AArrayOfGuID:TArrays); overload;
    class Procedure  ShowForm(AListPath : TList<string> ; AIndex :Integer );overload;

end;

var
  FrmShowPictureZoomIn: TFrmShowPictureZoomIn;

implementation

{$R *.fmx}

procedure TFrmShowPictureZoomIn.ARectCancelOnClick(Sender: TObject);
begin
  TDRForm.Create(TFrmShowPictureZoomIn).Release ;
end;

procedure TFrmShowPictureZoomIn.ARectOnClick(Sender: TObject);
var
  ABitmap : TBitmap ;
  AList   : TList<TBitmap>;
begin
  if Sender is TRectangle then
  begin
     try
        AList   := TList<TBitmap>.Create;
        ABitmap := TBitmap.Create;
        ABitmap.Assign(AImage[pageindex].bitmap);
        if AChkType.IsChecked <> true then
           ABitmap.CreateThumbnail(40,40);
        AList.Add(ABitmap);
        TMessageManager.DefaultManager.SendMessage(self,TImageCallBack.Create(AList));
        //image2.Bitmap.Assign(AImage[pageindex-1].bitmap);
     finally
       ABitmap.DisposeOf ;
     end;
  end;

end;

procedure TFrmShowPictureZoomIn.FormCreate(Sender: TObject);
begin
  pageIndex := 0;
  tapIsDown := false;
  LayoutContainer.Position.Y := 60;
  ARectIsCreate := false;
end;

procedure TFrmShowPictureZoomIn.FormGesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
  LObj   : IControl;
  LImage : TImage;
  LImageCenter : TPointF;
  ATag   : integer ;
begin
   INHERITED;
  {$IFNDEF MSWINDOWS}
   if Sender is TImage then
      ATag := TImage(Sender).Tag ;
   if Sender is TRectangle then
      ATag := TRectangle(Sender).Tag;
  if EventInfo.GestureID = igiZoom then
  begin
    tapIsDown := false;
    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
        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;
        //

if LImage.Width < FOriginalWidth[PageIndex] then
        begin
           FZoomWidth := LImage.Width ;
        end;
        if LImage.height < FOriginalHeight[PageIndex] then
        begin
           FZoomheight := LImage.height ;
        end;
      end;
      FLastDistance := EventInfo.Distance;
      Handled := true ;
    end;
  end;
  {$ENDIF}
end;

procedure TFrmShowPictureZoomIn.FormMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin

if FZoomWidth< FOriginalWidth[PageIndex] then
     begin
        AImage[PageIndex].Position.X := FOriginalX[PageIndex];
        AImage[PageIndex].Position.Y := FOriginalY[PageIndex] ;
        AImage[PageIndex].Width      := FOriginalWidth[PageIndex] ;
        AImage[PageIndex].Height     := FOriginalHeight[PageIndex] ;
     end;
end;

procedure TFrmShowPictureZoomIn.FormResize(Sender: TObject);
var
  i :integer ;
begin
  LayoutContainer.Height := Self.ClientHeight;
  LayoutContainer.Width  := self.ClientWidth ;
  RectTop.Width := trunc(self.ClientWidth / 3 );
  if ARectIsCreate then
  begin

if Assigned(FBitmapList) then
        for i :=0  to FBitmapList.Count -1  do
        begin
            ARect[i].Width := self.ClientWidth ;
            if i>0 then
              ARect[i].Position.X :=ARect[i-1].Width *I;
           ScrollMainView(FCurrentIndex);
        end;
     if Assigned(FImgListPath) then
        for i :=0  to FImgListPath.Count -1  do
        begin
            ARect[i].Width := self.ClientWidth ;
            if i>0 then
              ARect[i].Position.X :=ARect[i-1].Width *I;
           ScrollMainView(FCurrentIndex);
        end;
  end;
end;

procedure TFrmShowPictureZoomIn.FormTap(Sender: TObject; const Point: TPointF);
begin
  TDRForm.Create(self).Release ;
end;

procedure TFrmShowPictureZoomIn.ImgReturnClick(Sender: TObject);
begin
  TDRForm.Create(self).Release ;
end;

procedure TFrmShowPictureZoomIn.InitCurrentImage;
begin
  ScrollMainView(FCurrentIndex);
end;

procedure TFrmShowPictureZoomIn.InitCurrentImgPath;
begin

end;

procedure TFrmShowPictureZoomIn.InitCurrentPath;
begin
  TAnimator.AnimateFloat(LayoutContainer, 'Position.X', (50 * 2) * -1, 0.5, TAnimationType.Out, TInterpolationType.Exponential);
end;

procedure TFrmShowPictureZoomIn.InitFormInfo;
begin
  //PageCount  := FBitmapList.Count  ;
  if Assigned(FBitmapList) then
     begin
       PageCount := FBitmapList.Count -1 ;
       setLength(ArrayOfGuID,FBitmapList.Count,2);
     end;
  if Assigned(FImgListPath) then
     begin
       PageCount := FImgListPath.Count -1 ;
       setLength(ArrayOfGuID,FImgListPath.Count,2);
     end;
  {$IFNDEF MSWINDOWS}
     GestureManager1  := TGestureManager.Create(SELF) ;
  {$ENDIF}
end;

procedure TFrmShowPictureZoomIn.InitFormInfoA;
begin
  PageCount := FBitmapList.Count -1 ;
end;

procedure TFrmShowPictureZoomIn.InitImageList;
var
  i : integer ;
  ARect  : Array of TRectangle ;

ARectBottom : TRectangle;
  ARectTop    : TRectangle;
  ALblOk      : TLabel ;
begin
  setLength(ARect,FBitmapList.Count);
  setLength(AImage,FBitmapList.Count);
  setLength(FOriginalWidth,FBitmapList.Count);
  setLength(FOriginalHeight,FBitmapList.Count);
  setLength(FOriginalX,FBitmapList.Count);
  setLength(FOriginalY,FBitmapList.Count);
  for i := 0 to  FBitmapList.Count-1 do
  begin
    ARect[i] := TRectangle.Create(nil);
    ARect[i].Width := self.ClientWidth ;
    ARect[i].Height := self.Height ;
    ARect[i].Parent := LayoutContainer ;
    //ARect[i].Align  := TAlignLayout.Left ;
    if i>0 then
       ARect[i].Position.X :=ARect[i-1].Width *I;
    ARect[i].Tag    := i+1 ;
    ARect[i].Fill.Color :=$FF000000;
    {$IFNDEF MSWINDOWS}
    ARect[i].Touch.GestureManager := GestureManager1 ;
    ARect[i].Touch.InteractiveGestures :=[TInteractiveGesture.Zoom,TInteractiveGesture.Pan,TInteractiveGesture.Rotate,
                                          TInteractiveGesture.TwoFingerTap,TInteractiveGesture.PressAndTap];
    ARect[i].OnGesture   := FormGesture ;
    {$ENDIF}
    ARect[i].OnMouseDown := RectOnMouseDown ;
    ARect[i].OnMouseUp   := RectOnMouseUp ;
    ARect[i].OnMouseMove := RectOnMouseMove ;

AImage[i] := FMX.Objects.TImage.Create(nil);
    AImage[i].Parent := ARect[i] ;
    AImage[i].Tag    := i+1 ;
    AImage[i].Width  := self.ClientWidth -20 ;
    AImage[i].Height := 400 ;
    AImage[i].Margins.Left :=10;
    AImage[i].Margins.Right :=10;
    AImage[i].Align :=TAlignLayout.Center ;
//    if FileExists(FBitmapList[i]) then
//    begin
//      AImage[i].Bitmap.LoadFromFile(FBitmapList[i]);
//    end
//    else
      AImage[i].Bitmap.Assign(FBitmapList[i]);

AImage[i].WrapMode :=TImageWrapMode.Stretch ;
    AImage[i].HitTest  := true ;
    AImage[i].OnMouseDown := RectOnMouseDown ;
    AImage[i].OnMouseUp   := RectOnMouseUp ;
    AImage[i].OnMouseMove := RectOnMouseMove ;

ARectBottom := TRectangle.Create(nil);
    ARectBottom.Width := self.ClientWidth ;
    ARectBottom.Height := 60;
    ARectBottom.Parent :=  ARect[i] ;
    ARectBottom.StrokeThickness := 0;
    ARectBottom.Fill.Color := $FF000000;
    ARectBottom.Opacity := 0.5 ;
    ARectBottom.Align   := TAlignLayout.Bottom ;

ARectOK  := TRectangle.Create(nil);
    ARectOK.Parent := ARectBottom ;
    ARectOK.Width  := 120;
    ARectOK.Align  := TAlignLayout.Right ;
    ARectOK.HitTest := true;
    ARectOK.Margins.Top :=8;
    ARectOK.Margins.Right :=16;
    ARectOK.Margins.Bottom :=8;
    ARectOK.Sides :=[];
    ARectOK.XRadius := 8;
    ARectOK.YRadius := 8;
    ARectOK.Fill.Color := $FF4acfd6;
    ARectOK.OnClick    := ARectOnClick ;
    ALblOk      := TLabel.Create(nil) ;
    ALblOk.Text :='选 取';
    ALblOk.AutoSize := true;
    ALblOk.Parent   :=  ARectOK ;
    ALblOk.Font.Size  := 18;
    ALblOk.FontColor  := $FFFFFF;
    ALblOk.Align    := TAlignLayout.Center ;
    ALblOk.HitTest  := false;
    //
    ARectTop := TRectangle.Create(nil);
    ARectTop.Width := self.ClientWidth ;
    ARectTop.Height := 60;
    ARectTop.Parent :=  ARect[i] ;
    ARectTop.StrokeThickness := 0;
    ARectTop.Fill.Color := $FF000000;
    ARectTop.Opacity := 0.5 ;
    ARectTop.Align   := TAlignLayout.Top ;
    //
    FOriginalWidth[i]  := AImage[i].Width ;
    FOriginalHeight[i] := AImage[i].Height ;
    FOriginalX[i]      := AImage[i].Position.X ;
    FOriginalY[i]      := AImage[i].Position.Y ;
  end;

end;

procedure TFrmShowPictureZoomIn.InitImageListPath;
var
  i : integer ;
  ARectBottom : TRectangle;
  ARectTop    : TRectangle;
  ALblOk      : TLabel ;
  ALblCancel  : TLabel ;
  AStream     : TMemoryStream ;
begin
  setLength(ARect, FImgListPath.Count);
  setLength(AImage,FImgListPath.Count);
  setLength(FOriginalWidth, FImgListPath.Count);
  setLength(FOriginalHeight,FImgListPath.Count);
  setLength(FOriginalX,FImgListPath.Count);
  setLength(FOriginalY,FImgListPath.Count);
  ARectIsCreate      := true ;
  for i := 0 to  FImgListPath.Count-1 do
  begin
    ARect[i] := TRectangle.Create(nil);
    ARect[i].Width := self.ClientWidth ;
    ARect[i].Height := self.Height;
    ARect[i].Parent := LayoutContainer ;

ARect[i].HitTest:= true ;
    if i>0 then
       ARect[i].Position.X :=ARect[i-1].Width *I;
    ARect[i].Margins.Left :=20 ;
    ARect[i].Margins.Right :=20 ;
    ARect[i].Tag    := i+1 ;
    ARect[i].Fill.Color :=$FF000000;
    {$IFNDEF MSWINDOWS}
    ARect[i].Touch.GestureManager := GestureManager1 ;
    ARect[i].Touch.InteractiveGestures :=[TInteractiveGesture.Zoom,TInteractiveGesture.Pan,TInteractiveGesture.Rotate,
                                          TInteractiveGesture.TwoFingerTap,TInteractiveGesture.PressAndTap];
    ARect[i].OnGesture   := FormGesture ;
    {$ENDIF}
    ARect[i].OnMouseDown := RectOnMouseDown ;
    ARect[i].OnMouseUp   := RectOnMouseUp ;
    ARect[i].OnMouseMove := RectOnMouseMove ;

AImage[i] := FMX.Objects.TImage.Create(nil);
    AImage[i].Parent := ARect[i] ;
    AImage[i].Tag    := i+1 ;
    AImage[i].Align  :=TAlignLayout.Client ;
    AImage[i].WrapMode :=TImageWrapMode.Fit;
    //AImage[i].Align:=TAlignLayout.Contents;
    //AImage[i].Width  := self.ClientWidth ;
    //AImage[i].Height :=self.Height;

AStream:= TMemoryStream.Create ;
    {$IFDEF MSWINDOWS}
    if FileExists(FImgListPath[i]) then
    begin
      try
        AStream.LoadFromFile(FImgListPath[i]);
        AImage[i].Bitmap.LoadFromStream(AStream);
      finally
        AStream.DisposeOf ;
      end;
    end
    else
        AImage[i].Bitmap.Assign(Image2.Bitmap);
    {$ELSE}
    if TFile.Exists(FImgListPath[i]) then
    begin
      try
        AStream.LoadFromFile(FImgListPath[i]);
        AImage[i].Bitmap.LoadFromStream(AStream);
      Finally
        AStream.DisposeOf ;
      end;
    end
    else
      AImage[i].Bitmap.Assign(Image2.Bitmap);
    {$ENDIF}

//AImage[i].WrapMode :=TImageWrapMode.Stretch ;
    AImage[i].HitTest  := true ;
    AImage[i].OnMouseDown := RectOnMouseDown ;
    AImage[i].OnMouseUp   := RectOnMouseUp ;
    AImage[i].OnMouseMove := RectOnMouseMove ;

//
    FOriginalWidth[i]  := AImage[i].Width ;
    FOriginalHeight[i] := AImage[i].Height ;
    FOriginalX[i]      := AImage[i].Position.X ;
    FOriginalY[i]      := AImage[i].Position.Y ;
    ARectIsCreate      := true ;
  end;

end;

procedure TFrmShowPictureZoomIn.InitImageStrPath;
var
  i : integer ;
  ARect   : Array of TRectangle ;
  ALabel  : TLabel ;
  ARectBottom : TRectangle;
  ARectTop    : TRectangle;
  ALblOk      : TLabel ;
begin
  setLength(ARect,7);
  setLength(AImage,FBitmapList.Count);
  setLength(FOriginalWidth,FBitmapList.Count);
  setLength(FOriginalHeight,FBitmapList.Count);
  setLength(FOriginalX,FBitmapList.Count);
  setLength(FOriginalY,FBitmapList.Count);
  for i := 0 to  2 do
  begin
    ARect[i] := TRectangle.Create(nil);
    ARect[i].Width := 50;
    ARect[i].height := self.ClientHeight ;
    ARect[i].Parent := LayoutContainer ;
    //ARect[i].Align  := TAlignLayout.Left ;
    if i>0 then
    begin
        ARect[i].Position.X :=ARect[i-1].Width *I ;
    end;
    ARect[i].Tag    := i+1 ;
    ARect[i].Fill.Color :=$FF33aadd;
    ALabel  := TLabel.Create(nil);
    ALabel.Parent := ARect[i] ;
    ALabel.text := 'aa'+inttostr(i);
    ALabel.Align := TAlignLayout.Left ;

end;

end;

procedure TFrmShowPictureZoomIn.LblOkClick(Sender: TObject);
begin
  //
end;

procedure TFrmShowPictureZoomIn.lblSelectOKClick(Sender: TObject);
begin
  ARectOnClick(Sender);
end;

procedure TFrmShowPictureZoomIn.LoadImgGuIDInfo;
var
  getdata1: TGetData;
  str,devicetype,ANameList: string;
  Atag: string;
  cds1: TClientDataSet;
  AList :TStringList;
  i,j:integer;
begin
  if not IsWebConnected then
  begin
    ShowTips(NoAvailableNetwork);
    Exit;
  end;
  //  StartLoading(Self);
    ASYNCStart(
      procedure
      begin
        try
         // showmessage('P_DEC_getIMGDetail'+','+BMSCarrierObject_ID);
         getdata1 := TGetData.Create(['P_DEC_getIMGDetail',
                                      BMSCarrierObject_ID]);

str := getdata1.GetResult;
          cds1 := getdata1.GetClientDataSet;
        finally
          getdata1.DisposeOf;
        end;

SYNCStart(
        procedure
          begin
             try
                i:=0;
                cds1.First;
                while not cds1.Eof do
                begin
                    ArrayOfGuID[i,0]:= cds1.FieldByName('ID_SL').AsString;
                    ArrayOfGuID[i,1]:=cds1.FieldByName('ID').AsString;
                    inc(i);
                    cds1.Next;
                end;
                finally
                  // LoadZoomImg(FCurrentIndex);
                   cds1.disposeof;
             end;
          end);
      end);
end;

procedure TFrmShowPictureZoomIn.LoadZoomImg(AIndex: integer);
var
  i,j:integer;
  ABitmap:Tbitmap;
  errmsg:string;
begin
  //if firstHit<>0 then
  ScrollMainView(AIndex);
  ASYNCStart(
  procedure
  var
  j:integer;
      begin
          i:=AIndex;
          ABitmap:= Tbitmap.Create;
          for j := 0 to AGuIDlist.Count-1 do
          begin
            if ArrayOfGuID[j,0]=AGuIDlist[i] then
            begin

TBitmapManager.DownLoadSingleBitMap(ArrayOfGuID[j,1],ABitmap,errmsg);
            end;
          end;
          SYNCStart(
          procedure
          begin
             AImage[i].Bitmap.Assign(ABitmap);
            // firstHit:=1;
          end);

end);
end;

procedure TFrmShowPictureZoomIn.RectOnMouseDown(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  tapDownPos := TPointF.Create(X, Y);
  tapIsDown := true;
end;

procedure TFrmShowPictureZoomIn.RectOnMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Single);
begin
  if tapIsDown  then
  begin
     FX := LayoutContainer.Position.X ;
     if (PageIndex>=0) and (PageIndex<=PageCount) then
     begin

if X - tapDownPos.X  < 0 then
       begin
          TAnimator.AnimateFloat(LayoutContainer, 'Position.X', LayoutContainer.Position.X + (X - tapDownPos.x), 0.5, TAnimationType.InOut, TInterpolationType.Linear );
       end
       else
       begin
          TAnimator.AnimateFloat(LayoutContainer, 'Position.X', LayoutContainer.Position.X + (X - tapDownPos.x), 0.5, TAnimationType.InOut, TInterpolationType.Linear );
       end;
     end;
  end;
end;

procedure TFrmShowPictureZoomIn.RectOnMouseUP(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
  AMidX,AMidX1 :single ;
  ATag : integer ;
begin
   if FZoomWidth< FOriginalWidth[PageIndex] then
     begin
        AImage[PageIndex].Position.X := FOriginalX[PageIndex];
        AImage[PageIndex].Position.Y := FOriginalY[PageIndex] ;
        AImage[PageIndex].Width      := FOriginalWidth[PageIndex] ;
        AImage[PageIndex].Height     := FOriginalHeight[PageIndex] ;
     end;
  if tapIsDown then
  begin
     if Sender is TImage then
      ATag := TImage(Sender).Tag ;
     if Sender is TRectangle then
      ATag := TRectangle(Sender).Tag;

tapIsDown := false;
    if (pageIndex =0)  then
    begin
      if (X - tapDownPos.X + FX >0) then
         TAnimator.AnimateFloat(LayoutContainer, 'Position.X', 0, 0.5, TAnimationType.InOut, TInterpolationType.Circular )
      else
        if (X - tapDownPos.X + FX < -10) and (X - tapDownPos.X + FX > -80) then
           TAnimator.AnimateFloat(LayoutContainer, 'Position.X', 0, 0.5, TAnimationType.InOut, TInterpolationType.Linear )
        else
        begin
           Inc(pageIndex);

//   ScrollMainView(pageIndex);
        //   sleep(500);
           LoadZoomImg(pageIndex);
        end;
    end
    else
    begin

if (pageIndex = PageCount)   then
      begin

if X - tapDownPos.X + FX < 0 then
         begin   ///1111111111111
           if (X - tapDownPos.X + FX) + (self.ClientWidth * (pageindex)) <0 then
              TAnimator.AnimateFloat(LayoutContainer, 'Position.X', (self.ClientWidth*(PageCount))*-1, 0.5, TAnimationType.InOut, TInterpolationType.Linear )
           else
           begin
             if ((X - tapDownPos.X + FX) + (self.ClientWidth * (pageindex ))>0) and
                ((X - tapDownPos.X + FX) + (self.ClientWidth * (pageindex ))<100) then
             begin
               TAnimator.AnimateFloat(LayoutContainer, 'Position.X', (self.ClientWidth*(PageCount))*-1, 0.5, TAnimationType.InOut, TInterpolationType.Linear );
             end
             else
             begin
               Dec(pageIndex);
             //  ScrollMainView(pageIndex);
            //   sleep(500);
               LoadZoomImg(pageIndex);
             end;

end;
         end;
      end
      else
      begin
        // swipe left
        AMidX  := X - tapDownPos.X + FX ;
        AMidX1 := -(Self.ClientWidth*(pageIndex));
        if  AMidX - AMidX1 < 0  then
        begin
           if ((AMidX - AMidx1) < 0) and
              ((AMidX - AMidx1) > -120)  then
           begin
             TAnimator.AnimateFloat(LayoutContainer, 'Position.X', -(Self.ClientWidth*(pageIndex)), 0.5, TAnimationType.InOut, TInterpolationType.Linear );
           end
           else
           begin

Inc(pageIndex);
            // ScrollMainView(pageIndex);
            // sleep(500);
             LoadZoomImg(pageIndex);
           end;
        end
        // swipe right
        else
        begin
          if ((AMidX - AMidx1) > 0) and
              ((AMidX - AMidx1) < 80)  then
          begin
            ScrollMainView(pageIndex);
          end
          else
          begin
            dec(pageIndex);
          //  ScrollMainView(pageIndex);
           // sleep(500);
            LoadZoomImg(pageIndex);
          end;
        end;

end;
    end;
  end;

end;

procedure TFrmShowPictureZoomIn.RectTopClick(Sender: TObject);
begin
  TDRForm.Create(self).Release ;
end;

procedure TFrmShowPictureZoomIn.ScrollMainView(page: Integer);
begin
  //showmessage(pageIndex.ToString);
  pageIndex := page;
  Dec(page);
  TAnimator.AnimateFloat(LayoutContainer, 'Position.X', (ClientWidth * (page+1)) * -1, 0.5, TAnimationType.Out, TInterpolationType.Exponential);

end;

class procedure TFrmShowPictureZoomIn.ShowForm(AListPath: TList<string>;
  AIndex: Integer);
begin
  with TDRForm.Create(TFrmShowPictureZoomIn).TCCF as TFrmShowPictureZoomIn do
  begin
    FImgListPath  := AListPath ;
    FCurrentIndex := AIndex ;
    InitFormInfo ;
    Show ;
    InitImageListPath ;
    InitCurrentImage ;
  end;
end;

class procedure TFrmShowPictureZoomIn.ShowForm(AList: TList<TBitmap>;BGuIDlist:Tstringlist;
  AIndex: integer;AMSCarrierObject_ID:string; AArrayOfGuID:TArrays);
    var
    i,j:integer;
    ABitmap:Tbitmap;
    errmsg:string;
begin
  with TDRForm.Create(TFrmShowPictureZoomIn).TCCF as TFrmShowPictureZoomIn do
  begin
    firstHit:=0;
    FBitmapList   := AList ;
    FCurrentIndex := AIndex ;
    BMSCarrierObject_ID:=AMSCarrierObject_ID;
    InitFormInfo;
    Show ;
    AGuIDlist:=Tstringlist.Create;
    AGuIDlist:=BGuIDlist;
    ArrayOfGuID:=AArrayOfGuID;
    //LoadImgGuIDInfo;
    InitImageList ;
    //InitCurrentImage ;
    LoadZoomImg(FCurrentIndex);
//    ABitmap:= Tbitmap.Create;
//    for j := 0 to AGuIDlist.Count-1 do
//    begin
//      if ArrayOfGuID[j,0]=AGuIDlist[FCurrentIndex] then
//      begin
//         //showmessage(ArrayOfGuID[j,0]+','+ArrayOfGuID[j,1]);
//         TBitmapManager.DownLoadSingleBitMap(ArrayOfGuID[j,1],ABitmap,errmsg);
//        // image3.Bitmap.Assign(ABitmap);
//         AImage[FCurrentIndex].Bitmap.Assign(ABitmap);
//         firstHit:=1;
//      end;
//    end;
  end;
end;

end.