Loading many images

edited November 2013 in Android Mode

FATAL EXCEPTION: Animation Thread java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

Hello guys please what is the meaning of this error and how do i avoid it.I thinks it occurred when i loaded more images but i have only 10 images in my sketch i intend to have about 20 more all images are 1308 x 1308 pixels which i resize with variables screenHeight and screenWidth to make them smaller and proportional on different screens.

It compiles file but it does not run on the phone,the error appears in the processing ide when the app tries to run

Answers

  • 1308x1308 is nearly 7MBytes when decompressed, 4 bytes per pixel. and you have 10... resizing them means you probably have two copies of each.

    and be careful you aren't loading them repeatedly by having the loadImage()s in draw().

  • @koogs i'd like to ask what causes the "OutOfMemoryError" i suppose its not the amount of data because apps like instagram have about hundreds of minimized photos even when offline

  • Answer ✓

    The OutOfMemoryError is caused by... eating too much memory! Yes, it is because of the amount of data, as koogs said...

    Application like Instagram have probably optimizations, like generating the miniatures on a server, or on a storage device, etc. Loading a large image then resizing it results in having both the large image and the small one in memory.

    You can also change the memory settings, to increase them.

  • Answer ✓

    might also be that it's written using processing and not something more native. (that said, the native android apps are written in java anyway...)

    do the android development docs shine any light on this?

    maybe http://developer.android.com/training/displaying-bitmaps/index.html and children. it's android specific but has pointers.

    also lots of questions on stackoverflow.com. search for 'android many images' (that's where i got the above link).

  • OK.Thanks a lot guys

Sign In or Register to comment.