|
3 | 3 | import java.awt.AWTException; |
4 | 4 | import java.awt.Dimension; |
5 | 5 | import java.awt.DisplayMode; |
| 6 | +import java.awt.Graphics2D; |
6 | 7 | import java.awt.GraphicsConfiguration; |
7 | 8 | import java.awt.GraphicsDevice; |
8 | 9 | import java.awt.Rectangle; |
| 10 | +import java.awt.RenderingHints; |
9 | 11 | import java.awt.Robot; |
10 | 12 | import java.awt.image.BufferedImage; |
11 | 13 |
|
@@ -59,14 +61,28 @@ public Dimension getResolution() { |
59 | 61 |
|
60 | 62 | @Override |
61 | 63 | public void setResolution(Dimension size) { |
62 | | - // do nothings, screen has only one resolution which is already set |
| 64 | + resolution.setSize(size.getWidth(), size.getHeight()); |
63 | 65 | } |
64 | 66 |
|
65 | 67 | @Override |
66 | 68 | public BufferedImage getImage() { |
67 | 69 | final GraphicsConfiguration gc = device.getDefaultConfiguration(); |
68 | 70 | final Rectangle bounds = gc.getBounds(); |
69 | | - return robot.createScreenCapture(bounds); |
| 71 | + BufferedImage screen = robot.createScreenCapture(bounds); |
| 72 | + int width = resolution.width; |
| 73 | + int height = resolution.height; |
| 74 | + if (screen.getWidth() == width && screen.getHeight() == height) { |
| 75 | + return screen; // No need for adaption |
| 76 | + } |
| 77 | + BufferedImage img = new BufferedImage(width, height, screen.getType()); |
| 78 | + Graphics2D g = img.createGraphics(); |
| 79 | + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
| 80 | + RenderingHints.VALUE_INTERPOLATION_BILINEAR); |
| 81 | + g.drawImage(screen, 0, 0, width, height, |
| 82 | + 0, 0, screen.getWidth(), screen.getHeight(), |
| 83 | + null); |
| 84 | + g.dispose(); |
| 85 | + return img; |
70 | 86 | } |
71 | 87 |
|
72 | 88 | @Override |
|
0 commit comments