无法使用 swt Transform 旋转透明图像
我试图在画布上旋转 PNG 图像,旋转后图像的质量变得非常差。最初,PNG 是透明背景上的箭头。旋转后无法辨别它是箭头。
我使用以下代码:
Transform oldTransform = new Transform(
Display.getCurrent());
gc.getTransform(oldTransform);
Transform transform = new Transform(Display.getCurrent());
transform.translate(xm + imageBounds.width / 2, ym + imageBounds.height / 2);
transform.rotate(179);
transform.translate(-xm - imageBounds.width / 2, -ym - imageBounds.height / 2);
gc.setTransform(transform);
gc.drawImage(image, xm, ym);
gc.setTransform(oldTransform);
transform.dispose();
提前谢谢您。
I'm trying to rotate a PNG image on a canvas and the quality of the image becomes very bad after rotation. Initially the PNG is an arrow on a transparent background. After rotation it is impossible to tell that it is an arrow.
I use following code:
Transform oldTransform = new Transform(
Display.getCurrent());
gc.getTransform(oldTransform);
Transform transform = new Transform(Display.getCurrent());
transform.translate(xm + imageBounds.width / 2, ym + imageBounds.height / 2);
transform.rotate(179);
transform.translate(-xm - imageBounds.width / 2, -ym - imageBounds.height / 2);
gc.setTransform(transform);
gc.drawImage(image, xm, ym);
gc.setTransform(oldTransform);
transform.dispose();
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以水平和垂直翻转图像(无需任何像素转换),而不是将图像旋转 180 度:
编辑:或者更好的是,在单个操作中水平和垂直翻转(与旋转 180 度相同) :
Edit2: 还有一个特定于 SWT 的图像旋转/翻转示例,无需 Transform 也是。
Instead of rotating the image 180 degrees, you could flip it horizontally and vertically (without any pixel transformation):
Edit: or even better, flip both horizontally and vertically in single op (same as rotating 180 degrees):
Edit2: There is also SWT-specific example of image rotation/flipping without Transform too.