How to rotate image at a specific point by a certain angle in java?

skydarck

New Member
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());\[code\] 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);\[/code\]
 
Back
Top