Skip to content

Commit

Permalink
better scaling with Scalr
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-sita committed Nov 25, 2018
1 parent 9c44bc7 commit ee392c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@
<version>0.2</version>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<!-- pdfbox for opening pdfs-->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.12</version>
</dependency>

<!-- local dependency for kmeans-->
<dependency>
<groupId>pl.ksitarski.simplekmeans</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/simple_kmeans.jar</systemPath>
</dependency>

<!-- scaling images-->
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
17 changes: 4 additions & 13 deletions src/main/java/toolset/imagetools/BufferedImageScale.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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);
}

}

0 comments on commit ee392c8

Please sign in to comment.