0
在我的android應用程序中,當我從相機捕獲圖像時,我想重新調整它的尺寸。當我從畫廊拍攝圖像時,我很成功地重新調整大小。但是當我從相機捕捉時,我失敗了。請幫助從Android相機捕獲圖像時獲得更小尺寸的圖像
if (requestCode == take_image && resultCode == RESULT_OK && null != data) {
thumbnail = (Bitmap) data.getExtras().get("data");
image2 = me1;
addattachmentsToListView(image2);
}
這裏是從SD卡調整圖像的代碼:
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);
}
您是將圖像保存在設備上還是想調整從相機獲取的框架? – fasteque
@fasteque我想調整框架 – user2768215
檢查此http://stackoverflow.com/questions/20799901/creating-dcf-thumbnail-from-jpeg你在bmp中縮放圖像並再次創建scaled JPG。 –