我正在从" Gallery"中选择图像。或"拍照"。我的问题是,在使用相机拍照时背部按下。我收到了错误。
我的代码是
if (items[position].equals("Take photo")) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file= getOutputMediaFile();
Uri picUri = Uri.fromFile(file);
filepath = picUri.getPath();
i.putExtra(MediaStore.EXTRA_OUTPUT,picUri);
_a.startActivityForResult(i, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Log.e("Action", action);
if (action.equals("add_car")) {
if(_addLayout.filepath != null){
filePath = _addLayout.filepath;
_addLayout.filepath = null;
}
if(data != null)
filePath = CommonUtilities.getPath(data.getData(), "Image");
_addLayout.filepath = filePath;
setImage(UI_AddCar.ivTakenPicture);
}
}
void setImage(ImageView im){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
if(filePath != null){
int height = bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
im.setImageBitmap(imgbitmap);
im.setVisibility(View.VISIBLE);
} else {
im.setImageBitmap(bitmap);
im.setVisibility(View.VISIBLE);
}
}
在此UI_AddCar.ivTakenPicture中是ImageView
答案 0 :(得分:2)
感谢Piyush Gupta。我更新了条件如
if(filePath != null && bitmap != null){
int height = bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
im.setImageBitmap(imgbitmap);
im.setVisibility(View.VISIBLE);
}else {
im.setImageBitmap(bitmap);
im.setVisibility(View.VISIBLE);
}
}