简体   繁体   English

Android - 通过毕加索获取图像高度

[英]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,我在 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.我在 StackOverflow 上尝试了来自其他线程的各种解决方案,但不幸的是它们都不起作用。

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.在位图中加载图像,获取宽度和高度,然后在 imageView 中设置位图图像。 Glide library has the same feature. Glide 库具有相同的功能。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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