我正在尝试将捕获的图像的输出转换为uri,但是它会在另一个非空的组件上抛出空指针异常,之前和之后没有将图像存储在uri中它运行正常
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri1 = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"Photo" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri1);
cameraIntent.putExtra("return-data", true);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
和活动结果
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap temp=null;
Bundle extras = data.getExtras();
/*Uri g=data.getData();
try {
temp = MediaStore.Images.Media.getBitmap(getContentResolver(), g);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
*/
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
int h=photo.getHeight();
int w=photo.getWidth();
/* try {
temp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageCaptureUri1);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
bitmapdata = stream.toByteArray();
Log.i("image", ""+bitmapdata);
image_boolean=true;
stream.flush();
stream.close();
/*File f = new File(mImageCaptureUri1.getPath());
if (f.exists()) f.delete();*/
}catch(Exception e)
{}
imageView.setImageBitmap(photo);
}}
}