0

Possible Duplicate:
Rotating BufferedImage instances

The method I am currently using (below) results in a BufferedImage that becomes increasingly distorted with smaller angle arguments.

public static BufferedImage getRotatedImage(BufferedImage src, int angle) { 

    if (src == null) {

      System.out.println("getRotatedImage: input image is null");
      return null;

    }

    int transparency = src.getColorModel().getTransparency();
    BufferedImage dest =  gc.createCompatibleImage(
                              src.getWidth(), src.getHeight(), transparency );
    Graphics2D g2d = dest.createGraphics();

    AffineTransform origAT = g2d.getTransform(); 

    AffineTransform rot = new AffineTransform(); 
    rot.rotate(Math.toRadians(angle), src.getWidth()/2, src.getHeight()/2); 
    g2d.transform(rot); 

    g2d.drawImage(src, 0, 0, null);   

    g2d.setTransform(origAT);   
    g2d.dispose();

    return dest; 
Community
  • 1
  • 1
  • 1
    http://stackoverflow.com/questions/4156518/rotate-an-image-in-java The answer there isn't much? – Vova Lando Dec 31 '12 at 05:45
  • You could take a look at [this](http://stackoverflow.com/questions/11911610/affinetransform-rotate-how-do-i-xlate-rotate-and-scale-at-the-same-time/11911758#11911758) or [this](http://stackoverflow.com/questions/13964419/rotation-transform-not-working-properly-in-repaint-when-running-thread/13964860#13964860) or [this](http://stackoverflow.com/questions/12824684/change-the-angle-position-of-a-drawing-with-a-algorithm-in-java/12826882#12826882) – MadProgrammer Dec 31 '12 at 06:30
  • Are you clearing the image before drawing a new rotated version of it? – Extreme Coders Dec 31 '12 at 07:50

1 Answers1

1

that becomes increasingly distorted with smaller angle arguments.

Sounds like you're doing:

 img = base_img;
 for (i = 0; i < n; i++) {
   img = rotate(img, theta);
 }

When you really want to be doing:

for (i = 0; i < n; i++) {
  img = rotate(base_img, theta * n);
}

But I may be making assumptions that are untrue.

James
  • 8,512
  • 1
  • 26
  • 28