If you use them for fit-in screen display only, just scale them to the
screen-size. You don't need any bigger.

1. Figure out the actual width and height of the image
(inJustDecodeBounds = true)
2. When actually loading the pic, downsample (inSampleSize > 1) so
that the resulting image fits the screen as good as possible (for best
result, make the loaded image a bit bigger than the screen instead of
a bit smaller). Also, the values of inSampleSize work best across most
phones when its value is a power of 2 (2, 4, 8, etc)
3. Then scale the image (down) a bit further to exactly fit the
screen.

E.g. say your screen is 800x400. Your image is 2048x1536. Then
downsample the image (inSampleSize = 2) --> Loaded image is 1024x768.
Then scale the downsampled image by 52.08333% --> a bitmap of 533x400
pixels. Cache this image. Still, be careful not to cache too many
images.



On Feb 8, 9:48 am, Samuh <[email protected]> wrote:
> I have a bunch of image URLs. I have to download these images and
> display them in my application one-by-one. I am saving the images in a
> Collection using SoftReferences and also on Sdcard to avoid refetches
> and improve user experience.
>
> The problem is I dont know anything about the size of the bitmaps. And
> as it turns out, I am getting OutOfMemoryExceptions sporadically, when
> I am using BitmapFactory.decodeStream(InputStream) method. So, I chose
> to downsample the images using BitmapFactory Options(sample size=2).
> This gave a better output: no OOMs, but this affects the quality of
> smaller images.
>
> How should I handle such cases? Is there a way to selectively down
> sample only high resolution images?
>
> Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to