I'm having trouble resizing an image captured by the cell phone camera. The problem arises when I try to load the image in an ImageView with the result of this error: java.lang.OutOfMemoryError: Failed to allocate a 8294412 byte allocation with 7326352 free bytes and 6MB until OOM.
Obviously the image is too big, I tried to resize the image before it was loaded in the listview without success. does anyone know how to solve? this is the code I'm using:
Obviously the image is too big, I tried to resize the image before it was loaded in the listview without success. does anyone know how to solve? this is the code I'm using:
B4X:
Sub Camera1_PictureTaken (Data() As Byte)
Dim filename As String = "Camera1.jpg"
Dim dir As String = File.DirDefaultExternal
camEx.SavePictureToFile(Data,dir, filename)
tempBitmap=LoadBitmap(dir,filename)
StartActivity("ImageHomeImage")
LoadResult
End Sub
Sub CreateScaledBitmap2(Original As Bitmap, NewWidth As Int, NewHeight As Int) As Bitmap
Dim r As Reflector
tempBitmap= 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 tempBitmap
End Sub
Sub LoadResult
tempBitmap=CreateScaledBitmap2(tempBitmap,1920,1080)
ImageHomeImage.CameraTemp= tempBitmap
End Sub