1

I'm trying to load 30 images into a Bitmap array using BitmapFactory but no matter what I do I keep getting OutOfMemoryException.. I tried resizing it and doing the scale way down.. people usually do 4-8 I tried 12,16,20, nothing works..

I have a loop where it loads in a string of URLs and opens a new httpurlconnection each time around, downloads the image, and attempts to save it as a bitmap. the images are roughly 300kb each.

I've read other people having this issue with just one or two images so I'm not sure how what I'm looking to do is even possible.. I understand that jpegs and pngs are compressed format and the filesize is wayyy bigger on the phone because its an uncompressed bitmap, but there must be a way to efficently save a bunch of pictures in an array.. because i've seen it done before.

I tried the bitmap.recycle() and it took about 20 seconds to load, but didnt memoryerror, then when I tried viewing the image from the bitmap it gave me the 'cannot view recycled image' ?

Not sure if anyone else has tried to load many pictures (30-100) and save it in a bitmap array or if its even possible, but either way, let me know!

Thanks.

Jonny07
  • 625
  • 3
  • 14
  • Where did you see it done? – vault Feb 01 '13 at 20:17
  • I've seen a few apps with coverflows in android (which is what I'm using it for) but the coverflow library is very complex and it must be used with bitmaps. In the sample they use resources in the project and convert those to bitmaps, but in this case I'm downloading them using a httpurlconnection. – Jonny07 Feb 01 '13 at 20:19
  • I suppose I might just have to run a loop right when the app first loads, and download the images into the /tmp folder on disc or something.. then load them in the same way that the sample does.. although I'm not sure how much lag / bandwidth that would cause.. its quiet alot of pics.. – Jonny07 Feb 01 '13 at 20:23
  • While we find a solution, your chance is probably to store and recall them from a sqlite db. Anyway, I think remote images are already cached by Android after the first load. [Watch also these answers to load remote images](http://stackoverflow.com/questions/3075637/loading-remote-images) – vault Feb 01 '13 at 20:25
  • You will probably want to use the [library you find in the thread I just linked](https://github.com/codingfingers/fastimage), you can watch an example [here](https://play.google.com/store/apps/details?id=com.codingfingers.fastimage.examples.flicr) – vault Feb 01 '13 at 20:27
  • Ah sorry your right, I am already caching them, When the app first loads I'm downloading them all and loading them into a gridview using the UniversalImageLoader and I have caching enabled for it.. FYI I just checked the sample images and they are only 15-20kb.. so that probably explains why they work lol. – Jonny07 Feb 01 '13 at 20:29
  • If you are showing some sort of preview of your images, you should consider creating a small versions of them on the server. It doesn't make sense to load 200KB images in a 64x64 view :) – vault Feb 01 '13 at 20:35

1 Answers1

0

I solved this problem and thought I should help out anyone with the same issue.

I ended up using nostra13's "Universal Image Loader" - https://github.com/nostra13/Android-Universal-Image-Loader

To avoid the OOM errors, I loaded two separate sets of images from my API, one in full size, and one in thumbnail size(100x100 ish). I then load ALL the thumbnail size images for the gridview, and only load the full size INDIVDUAL image when the user clicks on a thumbnail. By doing it this way I've avoided all OOM errors. I'm also recycling the bitmaps I use before displaying the next one in the gridview.

Hopefully this helps :)

Jonny07
  • 625
  • 3
  • 14