簡體   English   中英

Android - 通過畢加索獲取圖像高度

[英]Android - get image height by Picasso

我在我的應用程序中無法正確顯示圖像。 我希望這幅畫能保持原來的比例。 我在 AppBar 中顯示圖片,

我正在使用畢加索下載圖像,但無法獲取下載圖像的高度和寬度。 我在 StackOverflow 上嘗試了來自其他線程的各種解決方案,但不幸的是它們都不起作用。

你能幫我用畢加索得到下載圖像的高度和寬度嗎?

您可以使用位圖目標。 在位圖中加載圖像,獲取寬度和高度,然后在 imageView 中設置位圖圖像。 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