2017-02-17 7 views
0

ピクチャを選択すると、BitmapFactory.decodeFileがnullを返します。 私の機能は次のとおりです。ピクチャを選択するときにBitmapFactory.decodeFileに関する問題が発生する

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Here we need to check if the activity that was triggers was the Image Gallery. 
    // If it is the requestCode will match the LOAD_IMAGE_RESULTS value. 
    // If the resultCode is RESULT_OK and there is some data we know that an image was picked. 
    if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && data != null) { 
     // Let's read picked image data - its URI 
     Uri pickedImage = data.getData(); 
     // Let's read picked image path using content resolver 
     String[] filePath = { MediaStore.Images.Media.DATA }; 
     Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null); 
     cursor.moveToFirst(); 
     String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0])); 

     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
     Bitmap bitmap = BitmapFactory.decodeFile(imagePath,options); 
     //imageView.setImageBitmap(bitmap); 

     // Do something with the bitmap 


     // At the end remember to close the cursor or you will end with the RuntimeException! 
     cursor.close(); 
    } 

} 

誰かが問題を教えていただけますか?

+0

あなたはあなたが何をしようとしているのかを具体的に教えてください – vishnumm93

+0

ギャラリーから画像を選んでビットマップを取得しようとしています – user2199630

答えて

0

String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));

あなたは変数IMAGEPATHでfilePathにあるのですか?またはimagePath値もnullですか? IMAGESIZEが大きすぎると、いくつかの例外をスローである可能性があるため

UPDATE
あなたBitmapFactory.decodeFile()はnullを返しています。
ログを確認して、outOfMemoryビットマップにエラーがあるかどうかを確認してください。私に知らせてください

+0

はい、imagePathがあります。/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20170217-WA0001.jpg – user2199630

+0

このエラーが発生します:/ BitmapFactory:ストリームをデコードできません:java.io.FileNotFoundException:/ storage/emulated/0/WhatsApp /メディア/ WhatsApp Images/IMG-20170217-WA0001.jpg:オープンに失敗しました: しかし、この行はマニフェストにあります: user2199630

+0

あなたはAPIレベル> = 23でお試しですか? –

関連する問題