Luban
Luban copied to clipboard
翻看代码,源文件文件流会多次打开srcImg.open(),但都没有关闭
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;
}
你改了吗?改了会不会有啥问题?
首先,流每次使用都要new一个新的。然后我自己实现了InputStreamProvider,在里面自己做了下处理,关闭了流。