0

I have a JPanel that paints an Image of a dice (java.awt.Image). I would like to rotate this image, but whenever it is rotated its edges become pixelated:

Rotated and not rotated images. The pixelation is even more visible than these images show.

Here is the paintComponent method:

public void paintComponent(Graphics g) {
    Graphics2D dicePainter = (Graphics2D) g;
    dicePainter.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int width = getWidth() / 2;
    int height = getHeight() / 2;
    dicePainter.rotate(-Math.PI / 3, width, height);
    super.paintComponent(g);
    dicePainter.drawImage(diceImage, 30, 15, ViewConstants.DICE_IMAGE_WIDTH, ViewConstants.DICE_IMAGE_WIDTH, this);
}

Is there anyway to improve the rendering when the image is rotated? I am thinking it is actually due to my screen resolution, rather than the Java image rendering as the more angled lines in the map also appear more pixelated than others.

KOB
  • 4,084
  • 9
  • 44
  • 88
  • 1
    Could you try : `g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);` ? I just found this in this topic : http://stackoverflow.com/questions/11159549/image-quality-gets-ruined-in-java-graphics2d-rotate?rq=1 – Arnaud Mar 02 '16 at 13:43
  • 1
    That woked nicely, looks a lot better! – KOB Mar 02 '16 at 14:34
  • [And](http://stackoverflow.com/questions/25577856/rotating-ball-loses-sharpness-and-colors/25581053#25581053) – MadProgrammer Mar 02 '16 at 17:47

0 Answers0