Sub Process_Globals
    ' Version 1.3 with markers in the angles
    Dim Left, Top, Right, Bottom, Width As Int
    Dim DeltaDot, Delta, DeltaX, DeltaY, StartX, StartY, MarkerDot, MarkerDot_1 As Int
    Dim fTopLeft, fTopRight, fBottomLeft, fBottomRight, fCenter As Boolean
    Dim colMarker As Int        : colMarker = Colors.RGB(255, 215, 0)
    Public PixelScale As Double
    Dim Chooser As ContentChooser
End Sub
Sub Globals
    Private btnSaveCroped As Button
    Dim imvImage As ImageView
    Dim pnlAction As Panel
    Dim cvsAction As Canvas
    Dim rectImage, rectOuter As Rect
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.Loadlayout("1") 
End Sub
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
    imvImage.Initialize("")
    Activity.AddView(imvImage, 0, 20%y, 100%x, 67%x)
    imvImage.Bitmap= LoadBitmap(File.DirAssets, "image0.jpg")
    imvImage.Gravity = Gravity.FILL
    pnlAction.Initialize("pnlAction")
    Activity.AddView(pnlAction, 0, 0, 100%x, 100%y )
    pnlAction.Color = Colors.ARGB(128, 0, 0, 0)
    cvsAction.Initialize(pnlAction)
    btnShow.Initialize("btnShow")
    Activity.AddView(btnShow, 50%x - 75dip, 100%y - 60dip, 150dip, 50dip)
    btnShow.Text = "Show image"
    Width = imvImage.Height
    Top = imvImage.Top
    Bottom = Top + Width
    Left = 50%x - Width / 2
    Right = Left + Width
    rectImage.Initialize(Left, Top, Right, Bottom)    ' square of croped bitmap
    rectOuter.Initialize(Left, Top, Right, Bottom)    ' outer square including the markers
    cvsAction.DrawRect(rectImage, Colors.Transparent, True , 1)    ' draws the transparent croped square
    DeltaDot = 10dip                            ' half of selection square
    MarkerDot = 6dip                            ' half of marker square
    MarkerDot_1 = MarkerDot + 1        ' half of marker square + 1 for outer square
    PixelScale = imvImage.Width / imvImage.Width
End Sub
Sub Button1_Click
    Chooser.Initialize("chooser")
    Chooser.Show("image/*", "Select an image")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub pnlAction_Touch (Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
        fTopLeft = False
        fTopRight = False
        fBottomLeft = False
        fBottomRight = False
        fCenter = False
        If X >= Left - DeltaDot And X <= Left + DeltaDot And Y >= Top - DeltaDot And Y <= Top + DeltaDot Then
            fTopLeft = True
            Activity.Title = "TopLeft"
        Else If X >= Left - DeltaDot And X <= Left + DeltaDot And Y >= Bottom - DeltaDot And Y <= Bottom + DeltaDot Then
            fBottomLeft = True
            Activity.Title = "BottomLeft"
        Else If X >= Right - DeltaDot And X <= Right + DeltaDot And Y >= Top - DeltaDot And Y <= Top + DeltaDot Then
            fTopRight = True
            Activity.Title = "TopRight"
        Else If X >= Right - DeltaDot And X <= Right + DeltaDot And Y >= Bottom - DeltaDot And Y <= Bottom + DeltaDot Then
            fBottomRight = True
            Activity.Title = "BottomRight"
        Else If X >= Left + DeltaDot And X < Right - DeltaDot And Y >= Top + DeltaDot And Y < Bottom - DeltaDot Then
            fCenter = True
            Activity.Title = "Center"
        End If    
        StartX = X
        StartY = Y
    Case Activity.ACTION_MOVE
        Dim Diff, Sign As Int
        DeltaX = X - StartX
        DeltaY = Y - StartY
        If Abs(DeltaX) >= Abs(DeltaY) Then
            Delta = DeltaX
        Else
            Delta = DeltaY
        End If
        cvsAction.DrawRect(rectOuter, Colors.Transparent, True , 1)
        cvsAction.DrawRect(rectOuter, Colors.ARGB(128, 0, 0, 0), True , 1)
        pnlAction.Invalidate2(rectOuter)
        If fCenter = True Then
            rectImage.Left = Left + DeltaX
            rectImage.Right = Right + DeltaX
            rectImage.Top = Top + DeltaY
            rectImage.Bottom = Bottom + DeltaY
            If rectImage.Left < imvImage.Left Then
                Diff = imvImage.Left - rectImage.Left
                rectImage.Left = imvImage.Left
                rectImage.Right = rectImage.Right + Diff
            End If
            If rectImage.Top < imvImage.Top Then
                Diff = imvImage.Top - rectImage.Top
                rectImage.Top = imvImage.Top
                rectImage.Bottom  = rectImage.Bottom + Diff
            End If
            If rectImage.Right >  imvImage.Left + imvImage.Width Then
                Diff = rectImage.Right - (imvImage.Left + imvImage.Width)
                rectImage.Right = imvImage.Left + imvImage.Width
                rectImage.Left  = rectImage.Left - Diff
            End If
            If rectImage.Bottom > imvImage.Top + imvImage.Height Then
                Diff = rectImage.Bottom - (imvImage.Top + imvImage.Height)
                rectImage.Bottom = imvImage.Top + imvImage.Height
                rectImage.Top  = rectImage.Top - Diff
            End If
        Else
            If fTopLeft = True Then
                If Left + Delta > imvImage.Left And Top + Delta > imvImage.Top Then
                    rectImage.Left = Left + Delta
                    rectImage.Top = Top + Delta
                End If
            End If
            If fTopRight = True And DeltaX <> 0 Then
                Sign = DeltaY / Abs(DeltaY)
                If Abs(DeltaX) >= Abs(DeltaY) Then
                    Delta = Abs(DeltaX) * Sign
                Else
                    Delta = DeltaY
                End If
                If Top + Delta > imvImage.Top And Right - Delta < imvImage.Left + imvImage.Width Then
                    rectImage.Top = Top + Delta
                    rectImage.Right = Right - Delta
                End If
            End If
            If fBottomLeft = True Then
                Sign = DeltaY / Abs(DeltaY)
                If Abs(DeltaX) >= Abs(DeltaY) Then
                    Delta = Abs(DeltaX) * Sign
                Else
                    Delta = DeltaY
                End If
                If Bottom + Delta < imvImage.Top + imvImage.Height And Left - Delta > imvImage.Left Then
                    rectImage.Bottom = Bottom + Delta
                    rectImage.Left = Left - Delta
                End If
            End If
            If fBottomRight = True Then
                If Bottom + Delta < imvImage.Top + imvImage.Height And Right + Delta < imvImage.Left + imvImage.Width Then
                    rectImage.Bottom = Bottom + Delta
                    rectImage.Right = Right + Delta
                End If
            End If
        End If
        cvsAction.DrawRect(rectImage, Colors.Transparent, True , 1)
        pnlAction.Invalidate2(rectImage)
        rectOuter.Initialize(rectImage.Left - MarkerDot_1, rectImage.Top - MarkerDot_1, rectImage.Right + MarkerDot_1, rectImage.Bottom + MarkerDot_1)
    Case Activity.ACTION_UP
        Left = rectImage.Left
        Top = rectImage.Top
        Right = rectImage.Right
        Bottom = rectImage.Bottom
        Activity.Title = ""
    End Select
End Sub
Private Sub GetImageCut
  """ !!Process To store the cut image, without resizing it Or distorting it just cut what you see inside the frame."""
End Sub
Private Sub btnShow_Click
    Dim imageCut As ImageView
    imageCut.Initialize("")
    Activity.AddView(imageCut, 0, 0, 100%y, 100%x)
    imageCut.Gravity = Gravity.FILL
End Sub