Android Question OutOfMemory Error with LoadBitmap

j_o_h_n

Active Member
Licensed User
I wrote an app that loads an image of an A4 sized document into a bitmap.
Another bitmap then has its InitializeMutable method run with the height and width of the first bitmap.

On a Huawei phone (model CUN-L01) which has android 5 there is no problem.
So it surprised me when on a Samsung Galaxy tab A (Model SM-T550) running Android 7, it caused an outOfMemory error.

When I got the error I saw that it was because my bitmap's dimensions are large and switched to using
the LoadBitmapResize method instead as was recommended.

This works fine except the bitmap is a little bit blurry when it's resized back to its original size afterwards.

I was wondering if this is happening just because my phone has more memory available or is it a difference between how android 5 and android 7 work?

B4X:
Dim Bm As Bitmap
Bm =   LoadBitmap(Main.sProgFolderPath & "/unsigned",document_show.selectedImage)
       
Dim Bmz As Bitmap
Bmz.InitializeMutable(Bm.Width,Bm.Height)

The code I used I took more or less verbatim from Erel's signature capture project


Thanks for any comments
 

Peter Simpson

Expert
Licensed User
Longtime User
Try using LoadBitmapSample instead...
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
A4 resolution is a huge (2480 x 3508 pixels)
and its bigger than any device screen in the market
try using LoadBitmapResize
if you must deal with the bitmap will this size add this line to your Manifest editor
B4X:
SetApplicationAttribute(android:largeHeap, "true")
 
Upvote 0

j_o_h_n

Active Member
Licensed User
Try using LoadBitmapSample instead...
Thanks Peter
I don't understand well enough to comment one way or the other, Erel recommends using LoadBitmapResize preferentially in all situations as far as I could see.

Can I use the LoadBitmapSample to use in conjunction with a canvas to draw a signature over a sample of a document and have that sample saved to the full document?
 
Upvote 0

j_o_h_n

Active Member
Licensed User
A4 resolution is a huge (2480 x 3508 pixels)
and its bigger than any device screen in the market
try using LoadBitmapResize
if you must deal with the bitmap will this size add this line to your Manifest editor
B4X:
SetApplicationAttribute(android:largeHeap, "true")

Thank you, I might just do this because the point of the app is signing A4 documents and it would be nice to not lose resolution by resizing them down and then back up
again
 
Upvote 0
Top