11

My app has to display a number of high resolution images (about 1900*2200 px), support pinch zoom. To avoid Out of memory error I plan to decode image to show full screen by using

options.inSampleSize = scale (scale was calculated as Power of 2 as Document)

(My view i used is TouchImageView extends of ImageView)

So i can quickly load image and swipe smoothly between screens(images). However, when i pinch zoom, my app loses detail because of scaled image. If i load full image, i can't load quickly or smoothly swipe, drag after pinch zoom. Then i try to only load full image when user begin pinch-zooming, but i still can't drag smoothly image because of very large image. Android gallery can do it perfectly even 8Mpx images.

Anyone can help me. Thanks in advance

Ajay S
  • 48,003
  • 27
  • 91
  • 111
Kiradev
  • 347
  • 2
  • 17
  • Maybe that's what you are looking for http://stackoverflow.com/questions/12022675/decode-part-of-jpeg-file – exebook Mar 02 '13 at 14:55
  • I don't understand deeply it but maybe it is not helpful for me – Kiradev Mar 02 '13 at 17:36
  • The (seemengly) only way to display huge Jpegs fast is to progressively load them and only decode the required parts. Common way to access jpeg is libjpeg, so the link above discusses how to use libjpeg to get progressively parts of the jpeg file without decoding it as a whole. – exebook Mar 04 '13 at 03:27
  • but libjpeg is written by C language. So is there another in Java? – Kiradev Mar 05 '13 at 03:03
  • Yes you can call C functions from Java, as explained here. http://stackoverflow.com/questions/12260149/libjpeg-turbo-for-android – exebook Mar 05 '13 at 04:41

2 Answers2

10

Sorry to answer an old question, but I've just completed an image view that shows an image from assets or external storage with subsampling, and loads higher resolution tiles from the image as you pinch to zoom in. As high resolution image data for areas of the screen is not loaded it should avoid out of memory exceptions.

https://github.com/davemorrissey/subsampling-scale-image-view

Dave Morrissey
  • 4,371
  • 1
  • 23
  • 31
  • I've just used your library and viewed the source code of it. You should get a Nobel prize! –  Jan 29 '14 at 18:15
  • works for small screens (320x480), but crashes for large ones (1280x800) :(. I really need a solution for loading a large image with zoom and panning. sigh... – M. Usman Khan Feb 24 '14 at 07:49
  • @usman Since I wrote this I've made some changes to fix some edge cases where an OOME could still be thrown. Several users have reported using the view to display images as big as 20,000x20,000 on any device. – Dave Morrissey Mar 14 '15 at 08:07
  • @DaveMorrissey i have been using your subsampling imageview project.can i get pixel value of the image using x,y coordinate. – Dinesh Kannan Mar 16 '15 at 14:17
3

I know the question was asked a long time ago but this answer might help other people struggling with this. I had exactly the same issue. You should consider using WebView and load your image with it, even if it is a local image. For instance to load an image in assets use the following:

// Get a WebView you have defined in your XML layout    
WebView webView = (WebView) findViewById(R.id.webView1);  
// Fetch the picture in your folders using HTML             
String htmlData = "<img src=\"my_image.png\">";
webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);
// Activate zooming
webView.getSettings().setBuiltInZoomControls(true);

I admit that it is very strange to use WebView for such a task, it is the only solution I found. At least you will never get an OOM exception.

Remi D
  • 501
  • 4
  • 17