-1

Whenever I try to show large size(1 MB) bitmap in imageview, system throw OutOfMemory exception.

If I place 7-8 MB image, gallery can easily show that image.

Just want to know How device default gallery is able to show large image in easy way?

  1. Which mechanism is used by device gallery?
Rohan Patel
  • 1,758
  • 2
  • 21
  • 38
  • possible duplicate of [How to manage set of images in memory cache?](http://stackoverflow.com/questions/25112237/how-to-manage-set-of-images-in-memory-cache) – Selvin Aug 06 '14 at 12:37
  • @Selvin: This is totally different question. FYI if u know the answer, why don't u give a answer for that question? – Rohan Patel Aug 06 '14 at 12:49
  • no, it just the same question, as "fartillion" other question here on SO which has one answer http://developer.android.com/training/displaying-bitmaps/index.html – Selvin Aug 06 '14 at 12:56

1 Answers1

0

Generally speaking, they subsample the image. A 1MB PNG or JPEG file will be much higher resolution than the screen, and so it is wasteful to load the whole image in. Subsampling allows you to load the image in much closer to the actual size of the ImageView you will use, allowing it to fit in memory better. A simple approach to subsampling involves using inSampleSize on BitmapFactory.Options; Dave Morrissey's SubsamplingScaleImageView offers pinch-to-zoom and such while peforming subsampling (note: I have not tried this component, as I just ran across it a minute ago).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thnx for immediate response. Is it use BitmapRegionDecoder to show large Bitmap? Is there any contact no. of ur, so i can contact u anytime directly. I m really a BIG fan of u. – Rohan Patel Aug 06 '14 at 12:43
  • @user3740000: Yes, if you know the region you want. It too supports subsampling via `inSampleSize` on the `BitmapFactory.Options` you supply to `decodeRegion()`. – CommonsWare Aug 06 '14 at 12:45
  • Do u have specific idea What approach to be used for cache and show 8 MB image with providing Pinch-Zoom. Any specific link or demo which do this type of thing efficiently? – Rohan Patel Aug 06 '14 at 12:53
  • @user3740000: That is all too broad for a Stack Overflow answer, let alone a comment. I already provided a link in my answer that covers your pinch-to-zoom scenario. – CommonsWare Aug 06 '14 at 12:59
  • Thnx Commonsware, I gone through the code and test app, its an amazing. Its provide similar functionality like device default gallery. I can't expect more than this. – Rohan Patel Aug 07 '14 at 10:29