简体   繁体   中英

Android - get image height by Picasso

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) {
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM