8

I am looking for a library or some idea on how I can load an image by parts from the disk or a url straight to the disk then in parts again to the ram. So the two ways I see that this can be done is loading the whole image onto the disk by reading and writing it from the url directly using the ram only for the buffer then when the image is on the disk some how creating bitmaps of only parts of the image, that way I DO NOT load it all and putting those in a ListView.

The issue is that I am dealing with extremely long images (10K + pixels long w/ a width of 4-600) and they hog up lots of ram if loaded all in one bitmap. I can not just scale them down like the Google android tutorial does in the handling large bitmaps section as that results in a width too small to deal with. So if I can somehow generate small bitmap slivers on the disk I can use them by loading them in a ListView preventing loading the image as a whole into ram.

Right now I am breaking the long images into slivers from a bitmap and I realized that that isn't really accomplishing what I am trying to do as the whole image is loaded into a bitmap in memory and is then broken up, then GC (So I am using up the full abmount of ram anyways). I am testing on a new top of the line android phone and the app works fine, but the heap size reaches 80mb+ with the larger images temporarily in ram as it breaks down the bitmap and this will be an issue with devices that have lower heap limits

Osman
  • 1,771
  • 4
  • 24
  • 47

4 Answers4

2

You can try using this class, support from 2.3 http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html

Binh Tran
  • 2,478
  • 1
  • 21
  • 18
  • wouldnt this require me to load the image into a bitmap into ram? Thats what I am trying to avoid. Thanks. – Osman Jun 12 '13 at 16:43
1

If you are using Java you can work with InputStreamReader and OutputStreamWriter. Method read() accepts the buffer as one of the parameters, its length can be anything suitable. Of course you can create a new file for each buffer being written.

Is it what you're looking for?

edit well its not. have you seen this Strange out of memory issue while loading an image to a Bitmap object ?

Community
  • 1
  • 1
tomasb
  • 1,663
  • 2
  • 22
  • 29
  • how will I know how much of the image I have in each part, I need to have slivers that are the width of the image and whatever height so I can set them in a listview – Osman Jun 03 '13 at 02:22
  • sorry I have been a little busy but I was not able to find a comprable android version to your code. Lets say png. – Osman Jun 04 '13 at 16:32
  • I just looked over the question you pointed to and its no help as using the down sizing method reduces height and width and to do that on a long image causes the width to be very small. By long image I am talking about 10k+ pixels. – Osman Jun 04 '13 at 21:11
0
  1. If you have control over the server from where you are fetching data, throw in another field in your response, such that it returns a thumbnail/smaller image. The server can then generate the required thumbnails for you, without you bothering about it.

  2. Decoding bitmaps on the fly might be expensive, most of the times. If you can't change anything on the server, download and save the images, and after saving, generate their corresponding thumbnails and save them as well. In your list, use the thumbnails. Also, save the information about which images have been cached, and whose thumbnails you already have. This might look like a lot of work, but depending on the use case, this can be a better approach dealing with large images.

Problem with downsizing? Well, you can come up with some kind of logic as to generate thumbnails, based on the original size of the image. For longer(vertically long images), you could use BitmpapRegionDecoder (http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html) as @Binh Tran has suggested.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
0

Try maybe encoding the image to make the size small.

COLD ICE
  • 840
  • 1
  • 12
  • 31