Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 379
Petr Župka Avatar asked Aug 18 '14 17:08

Petr Župka


1 Answers

Try adding some interpolation:

g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
like image 116
martinez314 Avatar answered Sep 28 '22 00:09

martinez314