comparison src/name/blackcap/imageprep/Menus.kt @ 15:fad32eda667f

Fix ImageWriter leak.
author David Barts <n5jrn@me.com>
date Sun, 19 Jul 2020 13:49:23 -0700
parents bed255e4c2dc
children d71523cde521
comparison
equal deleted inserted replaced
14:bed255e4c2dc 15:fad32eda667f
145 if (ios == null) 145 if (ios == null)
146 throw IOException() 146 throw IOException()
147 /* xxx - end workaround */ 147 /* xxx - end workaround */
148 ios.use { 148 ios.use {
149 val writer = ImageIO.getImageWritersByFormatName("jpeg").next() 149 val writer = ImageIO.getImageWritersByFormatName("jpeg").next()
150 val iwp = writer.getDefaultWriteParam().apply { 150 try {
151 setCompressionMode(ImageWriteParam.MODE_EXPLICIT) 151 val iwp = writer.getDefaultWriteParam().apply {
152 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) 152 setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
153 setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f)
154 }
155 writer.setOutput(it)
156 writer.write(null, IIOImage(w.image, null, null), iwp)
157 } finally {
158 writer.dispose()
153 } 159 }
154 writer.setOutput(it)
155 writer.write(null, IIOImage(w.image, null, null), iwp)
156 } 160 }
157 null 161 null
158 } catch (e: IOException) { 162 } catch (e: IOException) {
159 e 163 e
160 } 164 }