setImageBitmap 后图像不显示
Image not shown after setImageBitmap
我正在做一个 android 项目,我需要让用户拍照并将其作为个人资料照片
不知道是什么问题,拍完之后不显示了。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK)
{
Bitmap imageBitmap = (Bitmap) data.getExtras().get("date");
profilePicture.setImageBitmap(imageBitmap);
wasPhoto = true;
Toast.makeText(this, "Profile Picture taken successfully",
Toast.LENGTH_SHORT).show();
}
}
<ImageView
android:id="@+id/IVAddPicture"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/person_image" />
Before
After
在您的 onActivityResult 中尝试以下代码
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK
&& null != data) {
try {
Uri selectedImage = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mActivity.getContentResolver(), selectedImage);
profilePicture.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
}
我正在做一个 android 项目,我需要让用户拍照并将其作为个人资料照片 不知道是什么问题,拍完之后不显示了。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK)
{
Bitmap imageBitmap = (Bitmap) data.getExtras().get("date");
profilePicture.setImageBitmap(imageBitmap);
wasPhoto = true;
Toast.makeText(this, "Profile Picture taken successfully",
Toast.LENGTH_SHORT).show();
}
}
<ImageView
android:id="@+id/IVAddPicture"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/person_image" />
Before
After
在您的 onActivityResult 中尝试以下代码
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK
&& null != data) {
try {
Uri selectedImage = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mActivity.getContentResolver(), selectedImage);
profilePicture.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
}