【发布时间】:2019-07-09 04:23:24
【问题描述】:
我正在尝试选择要注册的图像。当点击ImageView 时,用户将可以选择是拍照还是从他/她的画廊中选择。当用户选择图库选项时,它将显示所选图像。当用户选择相机选项时,ImageView 不会显示图像。下面是我的OnActivityResult代码
protected void onActivityResult(int requestCode, int resultCode, Intent imgdata) {
super.onActivityResult(requestCode, resultCode, imgdata);
if (requestCode == SELECT_IMAGE && resultCode == RESULT_OK && imgdata != null) {
selectedimage = imgdata.getData();
try {
InputStream inputStream = getContentResolver().openInputStream(selectedimage);
Bitmap yourselectedimage = BitmapFactory.decodeStream(inputStream);
imgchild.setImageBitmap(yourselectedimage);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
}
}
if (requestCode == CAPTURE_IMAGE && resultCode == RESULT_OK && imgdata != null) {
camImg =(Bitmap) imgdata.getExtras().get("img");
try {
imgchild.setImageBitmap(camImg);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
}
}
}
ImageView 应该显示从相机拍摄的照片。
【问题讨论】:
-
您是否检查过
camImg是否为null? -
深度阅读photobasics。
标签: android android-camera android-imageview