0

我试过这个代码片段:

   if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CAMERA) {
            photoUri = capturedImagePath();
            Log.d("path to captured image", capturedImagePath().toString());
            Bitmap aBitmap = BitmapFactory.decodeFile(photoUri.toString());
            mProfilePic.setImageBitmap(aBitmap);
            mEncodedImageString = convertBitmapToString(aBitmap);
        Log.v("Base64 Image String : ", mEncodedImageString);

    } else if (requestCode == SELECT_FILE) {
        photoUri = data.getData();
        String[] filePathColumn = {
            MediaStore.Images.Media.DATA
        };
        Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null,
                null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        Bitmap aBitmap = BitmapFactory.decodeFile(picturePath);
        mProfilePic.setImageBitmap(aBitmap);
        mEncodedImageString = convertBitmapToString(aBitmap);
        Log.v("Base64 Image String : ", mEncodedImageString);
    }
}

获取图像路径,但它给了我原始图像。我想要的是所选图像的缩略图。谁能帮我实现同样的目标?

4

2 回答 2

1

您可以像这样轻松创建缩略图:

int thumbFactor = 4; // choose a power of 2
Bitmap thumb = Bitmap.createScaledBitmap(image, image.getWidth()/thumbFactor, image.getHeight()/thumbFactor, false);

位图

于 2013-08-19T01:23:17.103 回答
1

实际上,您无法通过 URI 查询获取缩略图。因为画廊自己缓存缩略图。如果您需要缩略图,您必须自己解码原始图像。

于 2013-08-19T02:59:48.947 回答