Java Swing:Graphics2D 旋转产生令人厌恶的边缘
我在图像旋转方面遇到问题,
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform at = new AffineTransform();
at.setToIdentity();
at.translate(x, y);
at.rotate(Math.toRadians(angle));
g2.transform(at);
image.paintIcon(c, g2);
我使用此代码在绘制图片之前旋转图片(图像是我创建的一个类,用于帮助我处理图片加载。
不幸的是,我在图像边缘遇到问题图像变得非常糟糕(参见图片)
有什么想法可以提高绘图质量吗?
杰森
I'm having a problem with the rotation of images
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform at = new AffineTransform();
at.setToIdentity();
at.translate(x, y);
at.rotate(Math.toRadians(angle));
g2.transform(at);
image.paintIcon(c, g2);
I use this code to rotate the picture before painting it (image is a class I created to help me handle loading of picture.
Unfortunately, I'm having a problem with the edges of the image that become really bad (cf Picture)
any ideas how I can improve the quality of the draw ?
jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试抗锯齿边缘和双线性变换怎么样?您可以在此处查看示例。另请检查您的图像类型,该示例使用
BufferedImage
。What about trying antialiased edges and bilinear transform? You can see an example here. Also check your type of image, the example uses a
BufferedImage
.据我所知,最高质量的渲染将通过打开抗锯齿功能(您已经完成)、将插值设置为
VALUE_INTERPOLATION_BICUBIC
并将渲染设置为VALUE_RENDER_QUALITY
来实现。From what I recall, the highest quality rendering will be driven by turning on anti-aliasing (which you've done), setting interpolation to
VALUE_INTERPOLATION_BICUBIC
and setting rendering toVALUE_RENDER_QUALITY
.