【发布时间】:2013-03-27 17:39:31
【问题描述】:
我正在尝试从图库中挑选一张图片,将其转换为 Bitmap,然后将其显示在 ImageView 中。
以下代码用于从图库中选择图片
Intent pickPhoto = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto, 1);`
在onActivityResult 中我将其转换为Bitmap 并在ImageView 中显示它
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;//returning null for below statement
bitmap = BitmapFactory.decodeFile(selectedImage.toString(), options);
productItemImage.setImageBitmap(bitmap);
}
break;
}
}
所选图像Uri中的值返回为“content://media/external/images/media/3647”
productItemImage 是我的ImageView,我在其中显示Bitmap。没有错误,但位图返回 null。
请帮忙
【问题讨论】:
标签: android bitmap android-imageview bitmapimage