BitmapFactory无法解码流空指针

时间:2013-09-06 02:22:22

标签: android

我使用以下代码拍摄图像并将其指定给ImageView。它在Kindle Fire HD(API 15)上完美运行,但在谷歌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);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

文件路径可能为空
Bitmap pic = BitmapFactory.decodeFile(filePath);

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

编辑:如果您遇到Picasa问题,可以在此处找到答案: Retrieve Picasa Image for Upload from Gallery