如何在java中以特定角度在特定点旋转图像?

时间:2013-03-23 06:06:24

标签: java image rotation graphics2d

我想围绕特定像素位置而不是图像中心旋转图像。我想将图像旋转一定程度小于90度。我已经使用了图形类的旋转功能,但是旋转时我的图像模糊了。如何消除这种模糊?这有特定的功能吗?这是我现在正在使用的代码:

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);

0 个答案:

没有答案