I am having trouble showing images correctly in my application. I wish the picture would retain its original proportions. I display picture in the AppBar,
I am using Picasso to download images, but cannot get the height and width of the downloaded image. I've tried various solutions from other threads on StackOverflow, but unfortunately none of them work.
Can you help me get the height and width of the downloaded image using Picasso?
You can use bitmap target. Load image in bitmap, get width and height and then set bitmap image in imageView. Glide library has the same feature.
Picasso.with(this).load(url).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
imageView.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});