画像をデコードするときにOOMエラーに苦労しています。このメッセージは私が扱っているものにぴったりです:BitmapFactoryOOMは私を狂わせます
私は自分の問題を何が解決するかは知っていると思いますが、それをどのように行うかはわかりません。今、画像のサイズを変更しているとき-次のようなビットマップを取得しています:
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
o2.inDither=false; //Disable Dithering mode
o2.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
o2.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
o2.inTempStorage=new byte[32 * 1024];
Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(file), null, o2);
そして、それをファイルに保存する必要があるよりも:
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
ご覧のとおり、私の目標はストレージ内の画像を減らすことです。
現在、大きなビットマップを操作すると、大きなファイルがメモリに読み込まれ、ヒープサイズが大きくなり、次の試行で、ネイティブヒープに十分なメモリがないため、OOM例外が発生します。
そこで、BitmapFactoryからストリームを取得し、それを何らかの方法でFileStreamに渡して保存したいと思います。大きなイメージが必要な場合は、VMヒープの問題が解消されます。
誰もが方法を知っていますか?