Mercurial > cgi-bin > hgweb.cgi > ImagePrep
comparison src/name/blackcap/imageprep/RotateDialog.kt @ 11:1f824742e1fa
Improve scaling quality.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 18 Jul 2020 08:12:00 -0700 |
parents | b5fcabce391f |
children | 26a507e095ab |
comparison
equal
deleted
inserted
replaced
10:70b4d11ebbb9 | 11:1f824742e1fa |
---|---|
4 package name.blackcap.imageprep | 4 package name.blackcap.imageprep |
5 | 5 |
6 import java.awt.Dimension | 6 import java.awt.Dimension |
7 import java.awt.Graphics | 7 import java.awt.Graphics |
8 import java.awt.Graphics2D | 8 import java.awt.Graphics2D |
9 import java.awt.RenderingHints | |
10 import java.awt.Toolkit | 9 import java.awt.Toolkit |
11 import java.awt.event.ActionListener | 10 import java.awt.event.ActionListener |
12 import java.awt.image.BufferedImage | 11 import java.awt.image.BufferedImage |
13 import java.io.File | 12 import java.io.File |
14 import java.io.IOException | 13 import java.io.IOException |
128 if (ratio >= 1.0) { | 127 if (ratio >= 1.0) { |
129 Pair(null, null) | 128 Pair(null, null) |
130 } else { | 129 } else { |
131 val nWidth = (imageIn.width * ratio).toInt() | 130 val nWidth = (imageIn.width * ratio).toInt() |
132 val nHeight = (imageIn.height * ratio).toInt() | 131 val nHeight = (imageIn.height * ratio).toInt() |
133 val imageOut = BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB) | 132 val imageOut = BufferedImage(nWidth, nHeight, imageIn.type) |
134 val graphics = imageOut.createGraphics().apply { | 133 imageOut.createGraphics().run { |
135 setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC) | 134 drawImage(imageIn.getScaledInstance(nWidth, nHeight, BufferedImage.SCALE_SMOOTH), 0, 0, null) |
136 setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY) | 135 dispose() |
137 setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) | |
138 } | 136 } |
139 graphics.drawImage(imageIn, 0, 0, nWidth, nHeight, null) | |
140 Pair(imageOut, null) | 137 Pair(imageOut, null) |
141 } | 138 } |
142 } catch (e: IOException) { | 139 } catch (e: IOException) { |
143 Pair(null, e) | 140 Pair(null, e) |
144 } | 141 } |