Stack Overflow archive
3 scoreaccepted

Picasso not showing Images from gallery on certain Samsung devices

score
3
question views
1.8K
license
CC BY-SA 3.0

You are most likely loading very large images which can lead to an OutOfMemoryError. You can resize the Bitmap and keep the aspect ratio.

Example of getting the width and height of a bitmap without loading it into memory:

java
File file = new File("/path/to/some/picture.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int width = options.outWidth;
int height = options.outHeight;

Tell Picasso to resize the image to avoid an OutOfMemoryError:

java
if (width > MAX_WIDTH || height > MAX_HEIGHT) {
    Picasso.with(context).load(uri)
        .resize(MAX_WIDTH, MAX_HEIGHT)
        .centerInside()
        .into(yourImageView);
}

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.