Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso fails to load large images (from Camera and local Uri)

I have a problem using Picasso trying to load large images from a local Uri of format content://com.android.providers.media.documents/document/imageXXYYZZ both from Gallery and Camera Intent.

I am loading the images with a standard call:

Picasso.load(image_url)
        .resize(600, 240)
        .centerCrop()
        .into(imageTarget);

I attached here a Target and when I am getting the onBitmapFailed(Drawable errorDrawable) error triggered. Also, when I log Picasso I get:

06-23 12:13:54.267  22393-22393/it.b3lab.friendipity D/Picasso﹕ Main        created      [R100] Request{content://com.android.providers.media.documents/document/image%3A13345 resize(600,240) centerCrop}
06-23 12:13:54.277  22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher  enqueued     [R100]+9ms
06-23 12:13:54.285  22393-23038/it.b3lab.friendipity D/Picasso﹕ Hunter      executing    [R100]+15ms
06-23 12:13:54.813  22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher  batched      [R100]+546ms for error
06-23 12:13:55.014  22393-23010/it.b3lab.friendipity D/Picasso﹕ Dispatcher  delivered    [R100]+746ms
06-23 12:13:55.024  22393-22393/it.b3lab.friendipity I/picasso﹕ failed to load bitmap
06-23 12:13:55.024  22393-22393/it.b3lab.friendipity D/Picasso﹕ Main        errored      [R100]+756ms

This only happens as I said above when I try to load large images from the gallery (above around 1 MB) and from the Camera intent when using a hi-res camera smartphone (in my case it's a Moto G running on Android 5.0.1). I am not getting this error using a Samsung S2 on Android 4.4.

Any help would be really appreciated! Thanks

like image 579
leo_lanzinger Avatar asked Jun 23 '15 10:06

leo_lanzinger


1 Answers

You need to resolve the content uri to an absolut uri. Eg like this:

public String getAbsolutePathFromURI( Uri contentUri ) {
  String[] proj = { MediaStore.Images.Media.DATA };
  Cursor cursor = activity.getContentResolver().query( contentUri, proj, null, null, null );
  int columnIndex = cursor.getColumnIndexOrThrow( MediaStore.Images.Media.DATA );
  cursor.moveToFirst();
  String path = cursor.getString( columnIndex );
  cursor.close();
  return path;
}
like image 145
Moritz Avatar answered Oct 15 '22 22:10

Moritz