After a user takes a picture with camera code, I create an ImageView and scale it to fit on a panel. Problem is that even when I scale it properly, no matter what gravity I select, the image is cropped and not all visible. This drives my users nuts, as they think their picture is smaller than they thought.
Can anyone help me to figure this out?
I see a thread from two years ago that seems to be the same problem (http://www.b4x.com/forum/basic4android-updates-questions/8601-imageview-images-fit-problem.html), but not an imageview solution.
Here's a snapshot of my code:
Can anyone help me to figure this out?
I see a thread from two years ago that seems to be the same problem (http://www.b4x.com/forum/basic4android-updates-questions/8601-imageview-images-fit-problem.html), but not an imageview solution.
Here's a snapshot of my code:
B4X:
Sub Globals
Dim pnlImage As Panel
End Sub
Sub Activity_Resume
pnlImage.RemoveAllViews
If File.Exists(File.DirRootExternal, "lobster.jpg" ) = True Then
Dim iv = CreateImageView( pnlImage, File.DirRootExternal, "lobster.jpg" ) As List
pnlImage.AddView( iv.get(0), iv.get(1), iv.get(2), iv.get(3), iv.get(4) )
End If
End Sub
Sub CreateScaledBitmap(Original As Bitmap, NewWidth As Int, NewHeight As Int) As Bitmap
Dim r As Reflector
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, NewWidth, NewHeight, True), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub
Sub CreateImageView( p As Panel, d As String, f As String ) As List
Dim scale As Float
Dim FullSizeBitmap As Bitmap
Dim ScaledBitmap As Bitmap
Dim iv As ImageView
Dim ReturnValue As List
Dim left, top, width, height As Int
FullSizeBitmap.initialize( d, f )
scale = Min ( p.width / FullSizeBitmap.width, p.height / FullSizeBitmap.height )
scale = Min( scale, 1 )
ScaledBitmap = CreateScaledBitmap( FullSizeBitmap, Floor( FullSizeBitmap.width * scale ), Floor( FullSizeBitmap.height * scale ) )
left = Floor( ( p.width - ScaledBitmap.width ) / 2 )
top = Floor( ( p.height - ScaledBitmap.height ) / 2 )
height = ScaledBitmap.height
width = ScaledBitmap.width
iv.Initialize("AddedImageViewEvents")
iv.Gravity = Gravity.CENTER
iv.Bitmap = ScaledBitmap
ReturnValue.Initialize
ReturnValue.Add( iv )
ReturnValue.Add( left )
ReturnValue.Add( top )
ReturnValue.Add( width )
ReturnValue.Add( height )
Return ReturnValue
End Sub