Mercurial > cgi-bin > hgweb.cgi > ImagePrep
diff src/name/blackcap/imageprep/Menus.kt @ 14:bed255e4c2dc
Fix file leak on save.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 19 Jul 2020 13:32:02 -0700 |
parents | 9e9fe34052a6 |
children | fad32eda667f |
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Menus.kt Sat Jul 18 14:23:02 2020 -0700 +++ b/src/name/blackcap/imageprep/Menus.kt Sun Jul 19 13:32:02 2020 -0700 @@ -145,13 +145,15 @@ if (ios == null) throw IOException() /* xxx - end workaround */ - val writer = ImageIO.getImageWritersByFormatName("jpeg").next() - val iwp = writer.getDefaultWriteParam().apply { - setCompressionMode(ImageWriteParam.MODE_EXPLICIT) - setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) + ios.use { + val writer = ImageIO.getImageWritersByFormatName("jpeg").next() + val iwp = writer.getDefaultWriteParam().apply { + setCompressionMode(ImageWriteParam.MODE_EXPLICIT) + setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) + } + writer.setOutput(it) + writer.write(null, IIOImage(w.image, null, null), iwp) } - writer.setOutput(ios) - writer.write(null, IIOImage(w.image, null, null), iwp) null } catch (e: IOException) { e