Search code examples
javaimagedrawantialiasingsmoothing

How can i draw smooth buffered images in java?


We're making a simple 2D game in Java. Every time we draw images they are jagged and look awful. We can anti-alias the text, but our images are in non-vector formats, so we can not apply anti-aliasing to them. We want to smooth our .JPG images (they were created with the maximum quality in Photoshop): is there a way to programmatically accomplish this?

enter image description here

BufferedImage goplaybut = ImageIO.read(getClass().getResourceAsStream("/gameover/goplaybut.jpg"));

g.drawImage();

Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

Solution

  • Try adding some interpolation:

    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);