display huge Images in Android display huge Images in Android android android

display huge Images in Android


I know it's an old post but I spent a lot of time on this problem, so here's my solution.

I wanted to display a 2000×3000 picture but I got out of memory or the image was too large to be displayed.

To begin, I get the dimensions of the picture:

o = new BitmapFactory.Options();o.inJustDecodeBounds=true;pictures = BitmapFactory.decodeStream(new FileInputStream(f), null, o);

Then I cut it up into four parts and displayed them with four ImageViews.I tried to load the full picture and cut it into four (using BitmapFactory.create(bitmap,int,int,int,int)) but got out of memory again.

So I decided to use some BitMapRegionDecoder:

for (int i = 0; i < 2; i++) {    for (int j = 0; j < 2; j++) {        ImageView iv = new ImageView(this);                 InputStream istream =   null;        try {         istream = this.getContentResolver().openInputStream(Uri.fromFile(f));        } catch (FileNotFoundException e1) {         e1.printStackTrace();        }        BitmapRegionDecoder decoder     =   null;        try {        decoder = BitmapRegionDecoder.newInstance(istream, false);        } catch (IOException e) {                    e.printStackTrace();        }    int nw = (j*width/k);    int nh = (i*height/k);    Bitmap bMap = decoder.decodeRegion(new Rect(nw,nh, (nw+width/k),(nh+height/k)), null);        iv.setImageBitmap(bMap);    }}

This worked.


I know its an old question but I used TileView to do exactly this:

https://github.com/moagrius/TileView


Try to use this one:https://github.com/davemorrissey/subsampling-scale-image-view

A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without OutOfMemoryErrors. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.