【问题标题】:BitmapFactory unable to decode stream null pointerBitmapFactory 无法解码流空指针
【发布时间】:2019-08-01 12:51:37
【问题描述】:

我使用以下代码获取图像并将其分配给 ImageView。它在 Kindle Fire HD (API 15) 上运行良好,但在 Google Nexus 7 上,该设备正在流式传输来自 Google 的 Picassa 的照片。如何让 Picassa/流式传输的照片正常工作?

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
protected void onActivityResult(int requestCode, int resultCode, 
           Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK){  
                Uri selectedImage = imageReturnedIntent.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 filePath = cursor.getString(columnIndex);
                cursor.close();


                Bitmap pic = BitmapFactory.decodeFile(filePath);

                mProfilePic = new BitmapDrawable(getResources(),pic);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                    mChangePicImgButton.setBackground(mProfilePic);
                else
                    mChangePicImgButton.setBackgroundDrawable(mProfilePic);
            }
        }
    }

【问题讨论】:

  • 它在哪里崩溃?如何?请记录下来。

标签: android


【解决方案1】:

filePath 在

处可能为空
Bitmap pic = BitmapFactory.decodeFile(filePath);

您确定该文件存在于设备上吗?

编辑:如果您在使用 Picasa 时遇到问题,这里有一个答案: Retrieve Picasa Image for Upload from Gallery

【讨论】:

  • 我只是在使用 Android 照片选择器 (photoPickerIntent.setType("image/*"); 然后我从设备中选择一张图片。适用于 Kindle 设备。
  • 看起来它崩溃的照片是从 Picassa“流式传输”的。那些在硬盘上的似乎可以工作。
  • @Spentak 显示您从 Picassa 获取图像的代码
  • 我不会从 Picassa 抓取图像 - Google 会自动抓取并在设备上流式传输它们。这是一个意想不到的变量 - 我没想到某些设备会有可流式传输图像的缩略图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-23
  • 2015-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多