Java:图形还是 Graphics2D?
我是 Java 新手,一直在尝试用它制作一些简单的游戏,屏幕上有很多图像。从那时起,我一直使用“Graphics”类来绘制这些图像、字符串和形状,但我最近遇到了 Graphics2D,它似乎是同一类东西。
谁能告诉我它们之间有什么区别,以及哪一个是最好用的吗?如果我想使用 Graphics2D,我是否必须对我的代码执行一些大型更新?
I am new to Java and have been trying to make some simple games in it with lots of images on screen. Since then I have been using the 'Graphics' class to draw these images, strings and shapes, but I recently came across Graphics2D which seems to be the same sort of thing..
Could anyone tell me what the difference is between them and which one would be the best to use? Would I have to perform some large updates for my code if I wanted to use Graphics2D?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递给paint(Graphics)的Graphics实际上是一个Graphics2D对象。如果您想使用任何 Graphics2D 功能,只需投射它并进行您需要的调用即可。
The Graphics that is passed to paint(Graphics) is actually a Graphics2D object. If you want to use any of the Graphics2D functionality, just cast it and make the calls you need.
Graphics2D 较新,可插入较新的 Java 2D api 集。除非必须向后兼容,否则请使用 Graphics2D。
Graphics2D is newer and plugs into the newer Java 2D api set. Use Graphics2D unless you have to be backwards compatible.