0

我使用以下代码拍摄图像并将其分配给 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);
            }
        }
    }
4

1 回答 1

0

filePath 可能为空

Bitmap pic = BitmapFactory.decodeFile(filePath);

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

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

于 2013-09-06T02:25:50.923 回答