我创建了一种从存储中选择图片的方法,当你选择图片时,图像被加载到imageview上,这个图像按预期工作,我有第二个问题,当我按下按钮相机已加载,我拍了照片,但是当我按下确定时,imageview没有加载图像,让我粘贴你的代码:
private static final int GALLERY_INTENT = 2;
private static final int CAMERA_INTENT = 3;
mtomarBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intento = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intento, CAMERA_INTENT);
}
});
mElegirFoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intento = new Intent(Intent.ACTION_PICK);
intento.setType("image/*");
startActivityForResult(intento, GALLERY_INTENT);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
uri= data.getData();
mImagenIv.setImageURI(uri);
} else if(requestCode == CAMERA_INTENT && resultCode == RESULT_OK){
Bitmap bitmap = (Bitmap) data.getExtras().get("Data");
mImagenIv.setImageBitmap(bitmap);
}
}
答案 0 :(得分:1)
替换:
Bitmap bitmap = (Bitmap) data.getExtras().get("Data");
使用:
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
额外名称是个案敏感的。