Skip to content

Commit cbc0f8d

Browse files
committed
Change image scaling algorythm
1 parent ed7ee90 commit cbc0f8d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/com/assertthat/selenium_shutterbug/utils/image/ImageProcessor.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import java.awt.*;
1111
import java.awt.color.ColorSpace;
12-
import java.awt.geom.AffineTransform;
1312
import java.awt.image.*;
1413

1514
/**
@@ -134,12 +133,11 @@ public static BufferedImage scale(BufferedImage source, double ratio) {
134133
int w = (int) (source.getWidth() * ratio);
135134
int h = (int) (source.getHeight() * ratio);
136135
BufferedImage scaledImage = getCompatibleImage(w, h);
137-
Graphics2D g2d = scaledImage.createGraphics();
138-
double xScale = (double) w / source.getWidth();
139-
double yScale = (double) h / source.getHeight();
140-
AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
141-
g2d.drawRenderedImage(source, at);
142-
g2d.dispose();
136+
Graphics2D resultGraphics = scaledImage.createGraphics();
137+
resultGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
138+
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
139+
resultGraphics.drawImage(source, 0, 0, w, h, null);
140+
resultGraphics.dispose();
143141
return scaledImage;
144142
}
145143

0 commit comments

Comments
 (0)