【问题标题】:BitmapFactory.decodeFile() returning null valueBitmapFactory.decodeFile() 返回空值
【发布时间】: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


【解决方案1】:

您是否在 minSdk 和 maxSdk 下方的 清单文件 中授予此类权限

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />

【讨论】:

    【解决方案2】:

    好的,所以我通过授予这些权限解决了问题。

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
    

    【讨论】:

      猜你喜欢
      • 2016-10-17
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多