Java2D负位置无法显示,将原点移至左下
我正在尝试在 Graphics2D 坐标系上画线。但是,我发现负数区域的线上部分无法显示。无论如何,我可以使负区域中的线条可见吗?
另外,我是否可以将 y 轴的直接从向下转换为向上?
Graphics2D g2 = (Graphics2D) g;
g2.scale(1, -1);
g2.translate(0, -HEIGHT);
无法工作。物体消失。
谢谢!
I am trying to draw lines on coordinates system in Graphics2D. However, I find out that the part on line in negative area can not be shown. Is there anyway I can make the lines in negative area be seen?
Also, is there anyway I can convert direct of y-axis from downward to upward?
Graphics2D g2 = (Graphics2D) g;
g2.scale(1, -1);
g2.translate(0, -HEIGHT);
Can't work. Object disappears.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊,您正在使用
HEIGHT
属性。您应该使用getHeight()
。下面的代码生成此屏幕截图 (
g2.drawLine(0, 0, 100, 100)
):代码:
Ah, you are using the
HEIGHT
attribute. You should be usinggetHeight()
.The code below produces this screenshot (
g2.drawLine(0, 0, 100, 100)
):Code:
据我了解 Java2D 你不能使用负坐标。你总是在Java2D中所谓的“用户空间”中进行操作。您在“设备空间”中的位置的平移坐标可能为负,但这在 Java 中对您来说是不可见的。另请参阅 Java2D 教程 - 坐标 和 Graphics2D API。
您也许可以通过子类化 Graphics2D 并自己进行这些转换来实现您想要的目标。
As far as I understand Java2D you can't use negative coordinates. You always operate in the so-called "User Space" in Java2D. The translates coordinates of your position in "Device Space" might be negative, but this is invisible to you in Java. See also Java2D Tutorial - Coordinates and Graphics2D API.
You might be able to achieve what you want by subclassing Graphics2D and doing the those translation yourself.