Luban icon indicating copy to clipboard operation
Luban copied to clipboard

翻看代码,源文件文件流会多次打开srcImg.open(),但都没有关闭

Open tm117898 opened this issue 7 years ago • 2 comments

File compress() throws IOException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = computeSize();

Bitmap tagBitmap = BitmapFactory.decodeStream(srcImg.open(), null, options);
ByteArrayOutputStream stream = new ByteArrayOutputStream();

if (Checker.SINGLE.isJPG(srcImg.open())) {
  tagBitmap = rotatingImage(tagBitmap, Checker.SINGLE.getOrientation(srcImg.open()));
}
tagBitmap.compress(focusAlpha ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG, 60, stream);
tagBitmap.recycle();

FileOutputStream fos = new FileOutputStream(tagImg);
fos.write(stream.toByteArray());
fos.flush();
fos.close();
stream.close();

return tagImg;

}

tm117898 avatar Dec 13 '18 07:12 tm117898

你改了吗?改了会不会有啥问题?

lovelyelfpop avatar Dec 24 '18 13:12 lovelyelfpop

首先,流每次使用都要new一个新的。然后我自己实现了InputStreamProvider,在里面自己做了下处理,关闭了流。

tm117898 avatar Dec 25 '18 09:12 tm117898