Tyler
Tyler

Reputation: 19848

Loading drawable from web file format to drawable, not using bitmap Android

I have a slight problem. I'm trying to dynamically load images (Jpeg, PNG, etc) from the web and display them in my Android App. This works 99% of the time. However, sometimes the images tend to be so large, that the bitmap blows through the available memory and causes OutOfMemoryExceptions.

I find that, even though a 3000px by 3000px Jpeg might be only 200 kilobytes, the resulting bitmap can be hundreds of megabytes. Is there a way to load Jpeg/PNG files from the web, into a drawable without converting to a bitmap first?

Upvotes: 0

Views: 581

Answers (1)

Sadegh
Sadegh

Reputation: 2669

Playing with bitmap in android is a little tricky, I highly recommend you to read THIS and THIS link from android developer site to get better idea how to load bitmap into memory efficiently. You can also use Universal Image Loader library which is very powerful and plugable library. It takes care of loading bitmap efficiently into memory and there are lots of configuration for you. It also download the image for you from the web.

  • You can set memory or disc cache for it. Also specify amount of cache size.
  • You can provide you custom image downloader for example in case you need authentication.
  • You can set FileNameGenerator for cache files.
  • You can set to consider ExifParams.
  • Set image scale type
  • UIL can load bitmap from file based on its ImageView container size. So you have better memory management. instead of loading a big size image, it will load a scaled down version of image base on ImageView size.

and lost of other options

Upvotes: 1

Related Questions