Display Huge Images in Android

Displaying Large Image in Android

This should do:

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

First, Add com.davemorrissey.labs:subsampling-scale-image-view:3.4.1
Second, instead of WebView, use it's custom ImageView:

<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Lastly, use setImage(ImageSource) method :

  SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.monkey));
// ... or ...
imageView.setImage(ImageSource.asset("map.png"))
// ... or ...
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));

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.

How to display large size bitmaps in imageview android?

Try using a WebView to show the image, instead of ImageView

How to display big image in Android

Thank you @MichaelShrestha for his link. Finally I found a way to display big image in Android by using BitmapRegionDecoder. Check this link for the sample code:
https://stackoverflow.com/a/12161993/190309

image too large to be displayed

You answered yourself, yes you have to scale your image, with picasso that's easy, anyway check this issue and the answer to check how to get the max texture size supported by a device.

Check this link to know how to resample images with picasso.



Related Topics



Leave a reply



Submit