diff 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
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/RotateDialog.kt	Fri Jul 17 23:25:33 2020 -0700
+++ b/src/name/blackcap/imageprep/RotateDialog.kt	Sat Jul 18 08:12:00 2020 -0700
@@ -6,7 +6,6 @@
 import java.awt.Dimension
 import java.awt.Graphics
 import java.awt.Graphics2D
-import java.awt.RenderingHints
 import java.awt.Toolkit
 import java.awt.event.ActionListener
 import java.awt.image.BufferedImage
@@ -130,13 +129,11 @@
                         } else {
                             val nWidth = (imageIn.width * ratio).toInt()
                             val nHeight = (imageIn.height * ratio).toInt()
-                            val imageOut = BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB)
-                            val graphics = imageOut.createGraphics().apply {
-                                setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
-                                setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
-                                setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
+                            val imageOut = BufferedImage(nWidth, nHeight, imageIn.type)
+                            imageOut.createGraphics().run {
+                                drawImage(imageIn.getScaledInstance(nWidth, nHeight, BufferedImage.SCALE_SMOOTH), 0, 0, null)
+                                dispose()
                             }
-                            graphics.drawImage(imageIn, 0, 0, nWidth, nHeight, null)
                             Pair(imageOut, null)
                         }
                     } catch (e: IOException) {