import java.awt.geom.*; static void paintFitBackground_smooth(Component c, Graphics _g, BufferedImage image) { Graphics2D g = cast _g; RenderingHints hints = g.getRenderingHints(); antiAliasOn(g); int w = c.getWidth(), h = c.getHeight(); int iw = image.getWidth(), ih = image.getHeight(); g.setColor(c.getBackground()); g.fillRect(0, 0, w, h); double imgScale = max(doubleRatio(h, ih), doubleRatio(w, iw)); double y1 = h-ih*imgScale; g.drawImage(scaleImage(image, imgScale), iround((w-iw*imgScale)/2), iround((h-ih*imgScale)/2), null); g.setRenderingHints(hints); }