我有ImageView
的图片是由用户从图库中选择的:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, GALLERY_REQUEST);
和:
@Override
protected void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if (resultCode == RESULT_OK) {
try {
final Uri imageUri = data.getData();
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
ImageView img = findViewById(R.id.img);
img.setImageBitmap(selectedImage);
//
ImageURI = Uri.parse(String.valueOf(imageUri));
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}
}else {
Toast.makeText(getApplicationContext(), "You haven't picked Image",Toast.LENGTH_LONG).show();
}
}
因为,我需要保存此图像的Uri以便以后使用,我创建了String
ImageURI,该值已分配给imageUri的字符串值(如上所示)
但是当我尝试将此图像加载到imageview时;
ImageView.setImageUri(ImageURI);
图像未加载。我没有任何错误。 我正在使用的示例Uri: content://com.miui.gallery.open/raw/%2storage%2Femulated%2F0%2FDCIM%2Camera%2FIMG_20190521_005650.jpg