簡體   English   中英

Android:顯示縮略圖的完整尺寸。

[英]Android: Display full-size version of thumbnail image.

我是android的新手,正試圖找出如何顯示被單擊的縮略圖的完整版本,我在這里處理本教程並且我真的很感謝任何指針,因為我不確定如何去做。

看看您的decodeSampledBitmapFromUri方法-這是加載照片的方法。

在您的情況下,您傳遞的reqWidthreqHeight較低,因此獲得的分辨率較低。 您可以將其傳遞給更大的尺寸以獲得更好的圖像(如屏幕寬度和高度),也可以僅使用options.inSampleSize = 1以獲得完整圖像

您可以為此使用BimapFactory。 我假設您具有文件的路徑以及所需的高度和寬度。

public static BitmapDrawable decodeSampledBitmapFromFile(Activity a, String path, float reqHeight, float reqWidth){
    final BitmapFactory.Options options = new BitmapFactory.Options();
    //you are not really creating the bitmap now but just calculating it's bounds
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;

    //options now holds the size needed to decode
    Bitmap bitmap = BitmapFactory.decodeFile(path, options);

    return new BitmapDrawable(a.getResources(), bitmap);
}

 public static int calculateInSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight){
    float srcWidth = options.outWidth;
    float srcHeight = options.outHeight;

    int sampleSize = 1;

    if(srcHeight > reqHeight || srcWidth > reqWidth){
        final float halfHeight = srcHeight / 2;
        final float halfWidth = srcWidth / 2;

        while((halfHeight / sampleSize) > reqHeight && (halfWidth / sampleSize) > reqWidth){
            sampleSize *= 2;
        }
    }

    return sampleSize;
}

從這里開始,就像將BitmapDrawble分配給視圖一樣簡單(通過view.setImageDrawable(drawble))

使它起作用:

BitmapDrawable b = decodeSampleBitmapFromFile(getActivity(), path, pictureWidth, pictureHeight);
view.setImageDrawable(b)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM