Hello,
I have the following question:
I am slowly with my advice at the end and would like to know if anyone has an idea how can I make the marketed area at xResizeAndCrop always the same width and high?
So if I change the size of the selection area height and width should always be the same.
I found an old example from Klaus, this works with older Version of ResizeAndCrop at https://www.b4x.com/android/forum/threads/resize-and-crop.19550/#post-113884
Does somebody has any idea?
The Old Code:
I have the following question:
I am slowly with my advice at the end and would like to know if anyone has an idea how can I make the marketed area at xResizeAndCrop always the same width and high?
So if I change the size of the selection area height and width should always be the same.
I found an old example from Klaus, this works with older Version of ResizeAndCrop at https://www.b4x.com/android/forum/threads/resize-and-crop.19550/#post-113884
Does somebody has any idea?
The Old Code:
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: ResizeAndCrop
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
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)
End Sub
Sub Globals
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)
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)
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
DrawMarkers
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)
DrawMarkers
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
Sub DrawMarkers
Dim r As Rect
r.Initialize(rectImage.Left - MarkerDot, rectImage.Top - MarkerDot, rectImage.Left + MarkerDot, rectImage.Top + MarkerDot)
cvsAction.DrawRect(r, colMarker, True , 1)
pnlAction.Invalidate2(r)
r.Initialize(rectImage.Right - MarkerDot, rectImage.Top - MarkerDot, rectImage.Right + MarkerDot, rectImage.Top + MarkerDot)
cvsAction.DrawRect(r, colMarker, True , 1)
pnlAction.Invalidate2(r)
r.Initialize(rectImage.Left - MarkerDot, rectImage.Bottom - MarkerDot, rectImage.Left + MarkerDot, rectImage.Bottom + MarkerDot)
cvsAction.DrawRect(r, colMarker, True , 1)
pnlAction.Invalidate2(r)
r.Initialize(rectImage.Right - MarkerDot, rectImage.Bottom - MarkerDot, rectImage.Right + MarkerDot, rectImage.Bottom + MarkerDot)
cvsAction.DrawRect(r, colMarker, True , 1)
pnlAction.Invalidate2(r)
End Sub