# Android QuestionxResizeAndCrop Scale Hight & Width

#### hasexxl1988

##### Active Member
Hello,
is it possible to adjust the width automatically to the height in a conscience proportion? And that this automatically goes with?

So almost like the square function. Only the choice is not square but 9 to 16.

Percent, the height and width should be that of Full HD So height 1920 and width 1080.

But if the image has a width of 2000 and a height of 549, he should automatically adjust the percentage down, so that the proportion of Full HD corresponds, only in a smaller resolution.

Thanks for Help i have tryd with:

B4X:
``````                If mSquare = False Then
If Abs(DeltaX) >= Abs(DeltaY) Then
Delta = DeltaX
Else
Delta = DeltaY
End If
'                    Log(Delta & " / " & DeltaX & " / " & DeltaY)
'                    Delta = Max(Abs(DeltaX), Abs(DeltaY))
If fTopLeft = True Then
If rLeft + Delta > imvImage.Left And rTop + Delta > ximvImage.Top Then
x1 = rLeft + Delta
y1 = rTop + Delta
If rectImage.Right - x1 >= mMinCroppedWidth And rectImage.Bottom - y1 >= mMinCroppedHeight Then
rectImage.Left = x1
rectImage.Top = y1
Else
rectImage.Left = rectImage.Right - mMinCroppedWidth
rectImage.Top = rectImage.Bottom - mMinCroppedHeight
End If
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 rTop + Delta > imvImage.Top And rRight - Delta < imvImage.Left + imvImage.Width Then
x1 = rRight - Delta
y1 = rTop + Delta
If rectImage.Bottom - y1 >= mMinCroppedHeight And rectImage.Bottom - y1 >= mMinCroppedHeight Then
rectImage.Top = y1
rectImage.Right = x1
Else
rectImage.Top = rectImage.Bottom - mMinCroppedHeight
rectImage.Right = rectImage.Left + mMinCroppedWidth
End If
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 rBottom + Delta < imvImage.Top + imvImage.Height And rLeft - Delta > imvImage.Left Then
y1 = rBottom + Delta
x1 = rLeft - Delta
If y1 - rectImage.Top > mMinCroppedHeight And rectImage.Right - x1 >= mMinCroppedWidth Then
rectImage.Bottom = y1
rectImage.Left = x1
Else
rectImage.Bottom = rectImage.Top + mMinCroppedHeight
rectImage.Left = rectImage.Right - mMinCroppedWidth
End If
End If
End If

If fBottomRight = True Then
If rBottom + Delta < imvImage.Top + imvImage.Height And rRight + Delta < imvImage.Left + imvImage.Width Then
y1 = rBottom + Delta
x1 = rRight + Delta
If y1 - rectImage.Top > mMinCroppedHeight And x1 - rectImage.Left >= mMinCroppedWidth Then
rectImage.Bottom = y1 * 1.777777777777778
rectImage.Right = x1
Else
rectImage.Bottom = rectImage.Top + mMinCroppedHeight
rectImage.Right = rectImage.Left + mMinCroppedWidth
End If
End If
End If
End If``````
Editet is: rectImage.Bottom = y1 * 1.777777777777778

The first time you resize it works. The second time errors occur

Edit:

I have found a easy way^^

B4X:
``````If fBottomRight = True Then
If rBottom + Delta < imvImage.Top + imvImage.Height And rRight + Delta < imvImage.Left + imvImage.Width Then
y1 = rBottom + Delta
x1 = rRight + Delta
If y1 - rectImage.Top > mMinCroppedHeight And x1 - rectImage.Left >= mMinCroppedWidth Then
If Firstclick = "OK" Then
rectImage.Bottom = y1
Else
rectImage.Bottom = y1 * 1.777777777777778
End If
rectImage.Right = x1
Else
rectImage.Bottom = (rectImage.Top + mMinCroppedHeight)
rectImage.Right = rectImage.Left + mMinCroppedWidth
End If
End If
End If``````
AND

B4X:
``````Case xpnlAction.TOUCH_ACTION_UP
rLeft = rectImage.Left
rTop = rectImage.Top
rRight = rectImage.Right
rBottom = rectImage.Bottom
If Firstclick = "" Then
Firstclick = "OK"
End If
If xui.SubExists(mCallBack, mEventName & "_CropFinished", 0) Then
CallSubDelayed(mCallBack, mEventName & "_CropFinished")
End If
End Select``````
Only the proportions are not right but that works too Last edited:

#### klaus

##### Expert
• 