0

I'm using following code for rotate my image

public class Field extends Canvas implements ActionListener {

    @Override
    public void paint(Graphics grphcs) {        
        super.paint(grphcs);         
        Graphics2D g2d = (Graphics2D) grphcs;
        AffineTransform affine = new AffineTransform();
        int angle = car.getAngle();
        Image image = car.getCarImage();       
        int x = (int) car.getX();
        int y = (int) car.getY();

        affine.rotate(Math.toRadians(angle), x + image.getWidth(null) / 2, 
               y + image.getHeight(null) / 2);
        g2d.setTransform(affine); 
        g2d.drawImage(image, x, y, null);     
    }  
    ....

if angle equals, for example, 5 image quality is lost.

enter image description here

What's the problem?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Terence
  • 69
  • 1
  • 11
  • This is probably an aliasing issue. To remedy this, you can enable various types of anti aliasing. Take a look at this, it should help: https://weblogs.java.net/blog/campbell/archive/2007/03/java_2d_tricker.html. – Martin Dinov Jan 10 '14 at 11:48
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Jan 10 '14 at 18:03

2 Answers2

1

You have to use antialiasing, try this:

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

example: the right icon is antialiased https://i.stack.imgur.com/svDR8.png

0

The other answers are half correct: Your problem can be solved by setting a RenderingHint. But in this case, it's not antialiasing.

Try adding this before you apply your transform:

g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                     RenderingHints.VALUE_RENDER_QUALITY);
VGR
  • 40,506
  • 4
  • 48
  • 63