0

I want to rotate an image about a specific pixel position and not about the centre of the image. I want to rotate the image by certain degrees less than 90. I've made use of rotate function of the graphics class but i get the image blurred when rotated. How to remove this blur? Is there a specific function for this? This is the code i am using right now:

BufferedImage oldImage = ImageIO.read(new File("C:/omr/OMR_Rotation_1.jpg"));

BufferedImage newImage = new BufferedImage(oldImage.getWidth(), oldImage.getHeight(),oldImage.getType());

            Graphics2D graphics = (Graphics2D) newImage.getGraphics();

            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
                    RenderingHints.VALUE_ANTIALIAS_DEFAULT);

            graphics.rotate(Math.toRadians(-2.3), newImage.getWidth() / 2, newImage.getHeight() / 2);

            graphics.translate((newImage.getWidth() - oldImage.getWidth()) / 2, (newImage.getHeight() - oldImage.getHeight()) / 2);

            //graphics.drawImage(oldImage, 0, 0, oldImage.getWidth(), oldImage.getHeight(), null);
            graphics.drawImage(oldImage, null, 0, 0);

            ImageIO.write(newImage, "JPG", new File("C:/omr/OMR_Rotation_2.jpg"));

            graphics.translate((newImage.getWidth() - oldImage.getWidth()) / 2, (newImage.getHeight() - oldImage.getHeight()) / 2);
Coder
  • 29
  • 5
  • 1
    possible duplicate of [How can you produce sharp paint results when rotating a BufferedImage?](http://stackoverflow.com/questions/6723929/how-can-you-produce-sharp-paint-results-when-rotating-a-bufferedimage) – FThompson Mar 23 '13 at 06:10
  • this page is a bit confusing. it seems like it deals with applets. is that rt? – Coder Mar 23 '13 at 06:51

0 Answers0