From ee392c820ef1fd75c9d15984ffbaab03b8845fc1 Mon Sep 17 00:00:00 2001 From: Sita Date: Sun, 25 Nov 2018 13:04:44 +0100 Subject: [PATCH] better scaling with Scalr --- pom.xml | 11 ++++++++++- .../AutomatedFilterController.java | 1 - .../toolset/imagetools/BufferedImageScale.java | 17 ++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 85d71d4..1597341 100644 --- a/pom.xml +++ b/pom.xml @@ -9,13 +9,14 @@ 0.2 - + org.apache.pdfbox pdfbox 2.0.12 + pl.ksitarski.simplekmeans sample @@ -23,6 +24,14 @@ system ${project.basedir}/src/main/resources/simple_kmeans.jar + + + + org.imgscalr + imgscalr-lib + 4.2 + + diff --git a/src/main/java/sections/automatedfilter/AutomatedFilterController.java b/src/main/java/sections/automatedfilter/AutomatedFilterController.java index fd45b13..d32ebe0 100644 --- a/src/main/java/sections/automatedfilter/AutomatedFilterController.java +++ b/src/main/java/sections/automatedfilter/AutomatedFilterController.java @@ -140,7 +140,6 @@ void previewPress(ActionEvent event) { var scaledOutput = BufferedImageScale.getScaledImage(output, width, height); Platform.runLater(() -> setNewImage(scaledOutput)); UserFeedback.reportProgress("Generated scaled preview."); - Platform.runLater(() -> GuiFileIO.saveImage(scaledOutput)); } else { Platform.runLater(() -> setNewImage(output)); UserFeedback.reportProgress("Generated preview."); diff --git a/src/main/java/toolset/imagetools/BufferedImageScale.java b/src/main/java/toolset/imagetools/BufferedImageScale.java index e66df2e..833fbd2 100644 --- a/src/main/java/toolset/imagetools/BufferedImageScale.java +++ b/src/main/java/toolset/imagetools/BufferedImageScale.java @@ -1,8 +1,11 @@ package toolset.imagetools; +import org.imgscalr.Scalr; + import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; +import java.awt.image.BufferedImageOp; public final class BufferedImageScale { @@ -50,20 +53,8 @@ public static BufferedImage getScaledImage(BufferedImage source, double scale) { public static BufferedImage getScaledImage(BufferedImage source, double width, double height) { if (source == null) return null; - BufferedImage newImage = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB); - - Graphics2D graphics2D = (Graphics2D) newImage.getGraphics(); - graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); - graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - - AffineTransform affineTransform = new AffineTransform(); - affineTransform.scale(width/source.getWidth(), height/source.getHeight()); - graphics2D.drawImage(source, affineTransform, null); - graphics2D.dispose(); - - return newImage; + return Scalr.resize(source, Scalr.Method.QUALITY, (int) width, (int) height, (BufferedImageOp) null); } }