Private iv As B4XImageView
Sub Button1_Click
Dim bmp As Bitmap
bmp.InitializeResize( File.DirAssets, "antes.jpg", 576,512, True) 'ignore
Dim r As B4XRect = FindMinRect(bmp)
Dim bmp2 As Bitmap = bmp.Crop(r.Left,r.Top,r.Width,r.Height)
iv.Bitmap = bmp2
Log(bmp.Width &"x"& bmp.Height)
Log(bmp2.Width &"x"& bmp2.Height)
End Sub
Sub FindMinRect (bmp As Bitmap) As B4XRect
Dim mxui As XUI
Dim bc As BitmapCreator
bc.Initialize(bmp.Width, bmp.Height)
bc.CopyPixelsFromBitmap(bmp)
Dim r As B4XRect
r.Initialize(bc.mWidth / 2, -1, bc.mWidth / 2, 0)
For y = 0 To bc.mHeight - 1
For x = 0 To bc.mWidth - 1
If bc.GetColor(x,y) <> mxui.Color_White Then ' IsTransparent(x, y) = False Then
r.Left = Min(r.Left, x)
Exit
End If
Next
If x < bc.mWidth Then
If r.Top = -1 Then
r.Top = y
Else
r.Bottom = y + 1
End If
For x = bc.mWidth - 1 To 0 Step -1
If bc.GetColor(x,y) <> mxui.Color_White Then ' IsTransparent(x, y) = False Then
r.Right = Max(r.Right, x + 1)
Exit
End If
Next
End If
Next
Return r
End Sub