我使用 MediaStore 拍了一张照片并保存了它。我可以在我的图库中看到该图像。但是,当我尝试将图像位图设置为 ImageView 时,它变为空白。
String abspath;
public void getPicture(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imageFile = new File(PATH + "/image.jpg");
abspath = imageFile.getAbsolutePath().toString();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(abspath)))
startActivityForResult(cameraIntent, RESULT_CAMERA);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
setContentView(R.layout.activity);
if(requestCode == RESULT_CAMERA) {
// open the image file
Bitmap bitmap = BitmapFactory.decodeFile(abspath);
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap); //imageView is now blank, although my saved image is not a blank image
//imageView.setImageURI(Uri.fromFile(new File(abspath))); same result
}
}