0

次のメソッドを使用してメモリ不足の例外を防ぎますが、ビットマップは常に null ではありません。誰にもアイデアはありますか?

public Bitmap readBitmap(Android.Net.Uri selectedImage) {

        Bitmap bm = null;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.InSampleSize = 9;
        AssetFileDescriptor fileDescriptor = null;
        try {
            fileDescriptor =  this.ContentResolver.OpenAssetFileDescriptor(selectedImage,"r");
        } catch (FileNotFoundException e) {
            Toast.MakeText(this, e.Message, ToastLength.Long);
        }
        finally{
            try {
                bm =  BitmapFactory.DecodeFileDescriptor(fileDescriptor.FileDescriptor, null, options);
                fileDescriptor.Close();
            } catch (IOException) {
            }
        }
        return bm;
}
4

4 に答える 4

0

おそらく、ウリは正しくなく、FileNotFoundException投げられます。show()ただし、catch句にToastのメソッドがないため、これは表示されません。

このようにする必要があります:

 Toast.MakeText(this, e.Message, ToastLength.Long).show();
于 2013-01-07T10:12:10.567 に答える
0

あなたのキャッチで、このように変更してみてください

} catch (IOException e) {
   Log.v ("Message", ""+e.message);
        }

だから、それがnullに返すというエラーが何であるかを見ることができました

于 2013-01-07T10:06:28.540 に答える
0

BitmapFactory.DecodeFileDescriptorbm が null の場合、例外をスローする必要があります。

于 2013-01-07T10:01:41.490 に答える