在我的 android 应用程序中,当我从相机捕获图像时,我想重新调整它的尺寸。当我从图库中获取图像时,我成功地重新调整了大小。但是当我从相机捕捉时,我失败了。请帮忙
if (requestCode == take_image && resultCode == RESULT_OK && null != data) {
thumbnail = (Bitmap) data.getExtras().get("data");
image2 = me1;
addattachmentsToListView(image2);
}
这是从 sdcard 调整图像大小的代码:
if (requestCode == UploadFile && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
try {
Bitmap image=(decodeUri(selectedImage));
addattachmentsToListView(image);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
getContentResolver().openInputStream(selectedImage), null, o);
final int REQUIRED_SIZE = 200;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 1.5 < REQUIRED_SIZE || height_tmp / 1.5 < REQUIRED_SIZE) {
break;
}
width_tmp /= 4;
height_tmp /= 4;
// width_tmp = 20;
// height_tmp = 20;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(
getContentResolver().openInputStream(selectedImage), null, o2);
}