big bitmaps, location of files, puzzled??!

boten

Active Member
Licensed User
Longtime User
Trying to load some big images into a bitmap and encountered this:
I have big.jpg which is 1000x1000 pixels and huge.jpg which is 3409x9000

bmp.Initialize(File.DirAssets,"big.jpg") ====> works
bmp.Initialize("/mnt/sdcard/external_sd","big.jpg") ====> works
bmp.Initialize(File.DirAssets,"huge.jpg") ====> works

but
bmp.Initialize("/mnt/sdcard/external_sd","huge.jpg") cause the app to "Stop Unexpectedly".

both big.jpg and huge.jpg DO EXIST on the external SD card.

Any thoughts?
 

boten

Active Member
Licensed User
Longtime User
Right. log has:
B4X:
.....
....
61362000-byte external allocation too large for this process.

VM won't let us allocate 61362000 bytes
--- decoder->decode returned false
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)

....
....
....
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
....
.....

1) But why it is OK when the huge file is "packed" (so to speak) with the apk when residing in the "files" sub-dir of the project, but FAILS when it is NOT in the "files" sub-dir but is read from external SD? the jpg have to be "expanded" to full size in memory in both cases.

2) Any way to "trick" the VM into allowing to allocate more space?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
That image must be huge > 50MB !!! 8kx2k?
Are we allowed to have apks that large?
I think it loads from DirAssets easily because the package is already in memory. (so it has probably already allocated all the memory it thinks it needs).
Loading from the sdcard may insert some limits due to bandwidth reasons.
Is it possible to cut the image in half and load them both in memory?
btw...I'm just speculating...
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
That image must be huge > 50MB !!! 8kx2k?
Are we allowed to have apks that large?
Actually the memory needed is slightly over 50MB, the log states it is 61362000 bytes, about 58.5MB :rolleyes:

But the APK is not that big since the bitmap is compressed in the jpg (jpg is less then 4MB). What puzzles me is that there's enough memory for the uncompressed bitmap when loaded with the apk (this is from the help file on bitmap: "Loading large bitmaps can easily lead to out of memory exceptions. This is true even if the file is compressed and not large as the bitmap is stored uncompressed in memory.")

Is it possible to cut the image in half and load them both in memory?
btw...I'm just speculating...
Of course it is, but eventually there will be some dozen huge bitmaps that need to be displayed (one at a time) and I thought it will be better to load them from the sd card rather then "packing" them in the apk. It also makes it easier to distribute modified bitmaps without re-distributing a very large APK.

Will have to figure out some other way to do that. :BangHead:
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Hmm...looks like some kind of memory allocation issue or limit...but afterall it is a massive bitmap!
I was saying, if you store your huge.jpg on the sdcard but split it into 2-4 parts you 'might' be able to load them, still not sure.
But now that you are saying you want to display a 'dozen' of this sized bitmaps...its not possible (58MB x 12 = 696MB) unless you have 1GB of RAM on your device, and besides, the screen is too small to display them fully
so I guess you need to only load a scaled down bitmap that you can display.
You can use Bitmap.InitializeSample as Erel said or use createScaledBitmap(http://www.b4x.com/forum/bugs-wishlist/11601-wish-implement-createscaledbitmap.html#post64884)
 
Upvote 0
Top