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
How to Start an Android Application from the Command Line
Caused By: Java.Lang.Outofmemoryerror: Bitmap Size Exceeds Vm Budget
How to Add a Switch to Android Action Bar
Calculate the Size of a List View or How to Tell It to Fully Expand
Phonegap Plugin:How to Convert Base64 String to a Png Image in Android
Play Rtsp Streaming in an Android Application
Fragment Already Added Illegalstateexception
Android Upload Video to Remote Server Using Http Multipart Form Data
Getfilesdir() VS Environment.Getdatadirectory()
Travis Ci Failed Because Cannot Accept License Constrain Layout
How Do We Distinguish Never-Asked from Stop-Asking in Android M's Runtime Permissions
How to Combine Bottomappbar + Fab with Bottomnavigationview
Android: When Is Oncreateoptionsmenu Called During Activity Lifecycle
The Application Icon Does Not Show on Action Bar
How to Set the Output Image Use Com.Android.Camera.Action.Crop