Android:显示缩略图图像的完整版本。

时间:2014-02-19 14:47:48

标签: android imageview thumbnails

我是Android的新手,我正在试图了解如何显示已点击的缩略图的完整尺寸版本,我正在使用本教程here并且非常感谢任何人指针,因为我不知道如何去做。

2 个答案:

答案 0 :(得分:0)

查看您的decodeSampledBitmapFromUri方法 - 这是加载照片的方法。

在您的情况下,您传递的是低reqWidthreqHeight,因此您可以获得低分辨率图像。 您可以传递更大的尺寸以获得更好的图像(例如屏幕宽度和高度),或者只使用options.inSampleSize = 1获取完整图像

答案 1 :(得分:0)

你可以使用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)
相关问题