0

我在用于测试的设备的 SD 卡上有一张照片。路径:

Uri selectedImageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/test/test/test1.jpg"));

(是的,文件已经存在于 SD 卡上)

我已经设法获得了 SD 卡上所有图像的缩略图,但我只想要这个特定的。

我该如何存档?

4

1 回答 1

3

这是创建缩略图的代码:

public static Bitmap decodeSampledBitmapFromFile(String path,
    int reqWidth, int reqHeight) { // BEST QUALITY MATCH

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);

// Calculate inSampleSize
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    int inSampleSize = 1;

    if (height > reqHeight) {
        inSampleSize = Math.round((float)height / (float)reqHeight);
    }

    int expectedWidth = width / inSampleSize;

    if (expectedWidth > reqWidth) {
        //if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
        inSampleSize = Math.round((float)width / (float)reqWidth);
    }


options.inSampleSize = inSampleSize;

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;

return BitmapFactory.decodeFile(path, options);
}
于 2013-03-06T15:45:49.420 回答