comparison 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
comparison
equal deleted inserted replaced
13:3feeb953d9ae 14:bed255e4c2dc
143 System.setOut(oldOut) 143 System.setOut(oldOut)
144 } 144 }
145 if (ios == null) 145 if (ios == null)
146 throw IOException() 146 throw IOException()
147 /* xxx - end workaround */ 147 /* xxx - end workaround */
148 val writer = ImageIO.getImageWritersByFormatName("jpeg").next() 148 ios.use {
149 val iwp = writer.getDefaultWriteParam().apply { 149 val writer = ImageIO.getImageWritersByFormatName("jpeg").next()
150 setCompressionMode(ImageWriteParam.MODE_EXPLICIT) 150 val iwp = writer.getDefaultWriteParam().apply {
151 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) 151 setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
152 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f)
153 }
154 writer.setOutput(it)
155 writer.write(null, IIOImage(w.image, null, null), iwp)
152 } 156 }
153 writer.setOutput(ios)
154 writer.write(null, IIOImage(w.image, null, null), iwp)
155 null 157 null
156 } catch (e: IOException) { 158 } catch (e: IOException) {
157 e 159 e
158 } 160 }
159 } 161 }