Android 安卓:从相机拍摄图像时会得到一个空值
我得到onActivityResult()中的“photoFile”为空 在“捕获”按钮上,单击我调用方法DispatchTakePictureContent() 但当我返回时,它将为空 当图像分辨率/大小非常大(如4012*4012等)时会出现此问题,尤其是在Android版本6.0上+ 这是我的密码Android 安卓:从相机拍摄图像时会得到一个空值,android,camera,Android,Camera,我得到onActivityResult()中的“photoFile”为空 在“捕获”按钮上,单击我调用方法DispatchTakePictureContent() 但当我返回时,它将为空 当图像分辨率/大小非常大(如4012*4012等)时会出现此问题,尤其是在Android版本6.0上+ 这是我的密码 private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = Util.createImageFile();
mCurrentPhotoPath = photoFile.getAbsolutePath();
System.out.println( "photoFile:" + photoFile.getAbsolutePath());
} catch (IOException ex) {
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
System.out.println("@@@@ photoFile: " + photoFile.getAbsolutePath());
/*takePictureIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT,1024);
takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
mCurrentPhotoPath);*/
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
try {
//Bundle extras = data.getExtras();
// Log.i(TAG, "extras: " + extras.get("data"));
Bitmap mphoto = (Bitmap) data.getExtras().get("data");
System.out.println( "***photoFile: " + data.getExtras().get("data"));
} catch (Exception e) {
// Log.i(TAG, "Exception:" + e.getMessage());
}
ShowPopupDialog(mCurrentPhotoPath);
}
}
}
请帮帮我。提前感谢。将您的
OnActivityResult
代码更改为:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
try {
File fil = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : fil.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
fil = temp;
break;
}
}
Bitmap bitmap = null;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
Bitmap bmp = BitmapFactory.decodeFile(fil.getAbsolutePath(),bitmapOptions);
//
Log.e("edit", "new image path is " + fil.getAbsolutePath());
} catch (Exception e) {
// Log.i(TAG, "Exception:" + e.getMessage());
}
ShowPopupDialog(mCurrentPhotoPath);
}
}
错误是:无法解码流:java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“char[]java.lang.String.toCharArray()”