【发布时间】:2015-05-19 12:56:11
【问题描述】:
在我的应用程序中,我从图库中选择图像并将其设置为图像视图。问题是图像未显示在图像视图中。我已经调试了问题但应用程序,所以我发现方法 BitmapFactory.decodeFile("image path") 正在返回 null 值,即使我得到的路径完全没问题。
代码
case R.id.imageView:
intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, GALLERY_CODE);
break;
if (requestCode == GALLERY_CODE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap image = BitmapFactory.decodeFile(picturePath);
ivImage.setImageBitmap(image);
}
}
我不知道为什么会这样。 请帮帮我
【问题讨论】:
-
您是否使用调试模式检查过 'picturePath' 的值
-
是的,我正在获取图片的路径
-
兄弟在下面查看我的解决方案:-
标签: android imageview bitmapfactory