6

現在、次の問題が発生しています。ギャラリーから画像を取得する場合は、次のコードを使用してギャラリーのインテントを開始します。

public void useGallery() {
    this.intentbasedleave=true;
    Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(
            Intent.createChooser(intent, getString(R.string.pleaseselect_image)), IMAGE_PICK);
}

ギャラリーからデータを取得するときは、次の方法を使用します。

private void imageFromGallery(int resultCode, Intent 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 filePath = cursor.getString(columnIndex);
    cursor.close();

    this.updateImageView(BitmapFactory.decodeFile(filePath));
}

選択した画像がGoogle+またはインスタントアップロードからのものでない限り、これは機能します。次に、BitmapFactory.decodeFile(filePath))はnullのように見えますか?メソッドがnullpointer例外を発生させるため。

したがって、私の質問は、Google+およびギャラリーからのインスタントアップロードからの画像をどのように使用できるかということです。

4

1 に答える 1

1

BitmapFactory.decodeUriの代わりに使用してくださいBitmapFactory.decodeFile

あなたはあなたの方法imageFromGalleryを単純化することができます

private void imageFromGallery(int resultCode, Intent data) {
  Uri selectedImage = data.getData();
  updateImageView(BitmapFactory.decodeUri(getContext().getContentResolver(), selectedImage));
}

(どこかからコンテキストにアクセスできると仮定します)。

于 2013-09-30T16:03:55.003 に答える