0

I need to set image to my image view

For this reason I use Picasso library

Here is approach how I do this

File image = new File("file:" + path);
    Picasso.with(context)
            .load(image)
            .placeholder(R.drawable.progress_animation)
            .error(R.drawable.image_error_404)
            .into(iv);

and also I tried the same without prefix file: like here

File image = new File(path);
    Picasso.with(context)
            .load(image)
            .placeholder(R.drawable.progress_animation)
            .error(R.drawable.image_error_404)
            .into(iv);

But all the time I got image from .error() ,

There is a path with file: prefix - "file:/storage/emulated/0/Android/data/com.fittingroom.newtimezone/files/default/AvatarPackage/DEFAULT_MY_AVATAR/pose1.jpeg"

and there is path witout file: prefix - "/storage/emulated/0/Android/data/com.fittingroom.newtimezone/files/default/AvatarPackage/DEFAULT_MY_AVATAR/pose1.jpeg"

Anyway I got no result

Why picasso doesn't want to set my image

What am I doing wrong?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • 1
    Does `image.exists()` return `true` or `false`? Have you tried adding [the global listener](http://stackoverflow.com/a/31608813/115145) to get the exception that is triggering the error response? – CommonsWare Feb 23 '17 at 13:55
  • @CommonsWare ok, thanks I now I understand what is the reason - OOM , image is too big... But it is strange, why Picasso did not processing such case... Because for example Glade did not encounter with such error... Ok, is it means that I need resize image or maybe I can add some parameters? – Sirop4ik Feb 23 '17 at 14:19
  • AFAIK, Picasso should be resizing based on the size of the target `ImageView`. There are manual options for that (e.g., `.resize()`) as well. – CommonsWare Feb 23 '17 at 14:43

2 Answers2

0

Your path prefix is incorrect: use file:/// instead of file:

Anurag Singh
  • 6,140
  • 2
  • 31
  • 47
0

Thanks @CommonsWare I solve my issue such way

.fit()
.centerInside()

And here is my implementation

File image = new File(path);

    Picasso picasso = new Picasso.Builder(context)
            .listener(new Picasso.Listener() {
        @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            Logger.logError("ERROR Download image: ", exception, context);
        }
    }).build();

    picasso
            .load(image)
            .fit()
            .centerInside()
            .placeholder(R.drawable.progress_animation)
            .error(R.drawable.image_error_404)
            .into(iv, new Callback() {
                @Override public void onSuccess() {
                    Logger.logGeneral("image downloaded");
                }

                @Override public void onError() {
                    Logger.logGeneral("onError image downloaded");
                }
            });
Sirop4ik
  • 4,543
  • 2
  • 54
  • 121