如何给像素着色?
我必须创建一个简单的 2D 动画,而不使用各种图元来绘制线条、圆形等。它必须通过操纵像素并通过对像素着色来实现绘制线条、圆形等的算法之一来完成。
我想过使用 Turbo C 来达到目的,但我使用 ubuntu。所以我尝试使用dosbox安装并运行turbo C但无济于事。
现在我唯一的选择是Java。 Java 中可以操作像素吗?我找不到任何好的教程。如果可以给出相同的示例代码,那就太好了。
I have to create a simple 2D animation without using various primitives for drawing line, circle etc for the purpose. It has to be done by manipulating pixels and implementing one of the algorithms for drawing line, circle etc by coloring pixels.
I thought of using Turbo C for the purpose, but I use ubuntu. So I tried using dosbox to install and run turbo C but to no avail.
Now my only option is Java. Is it possible to manipulate pixels in Java? I couldn't find myself any good tutorials for the same. It would be great if a sample code for the same can be given.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
类
java.awt.BufferedImage< /code>
有一个方法
setRGB(int x, int y, int rgb)
,它设置单个像素的颜色。此外,您可能需要查看java.lang. awt.Color
,尤其是它的getRGB()
方法,它可以将 Color 转换为整数,然后将其放入int rgb
参数中代码>设置RGB。The class
java.awt.BufferedImage
has a methodsetRGB(int x, int y, int rgb)
which sets the color of an individual pixel. Additionally, you might want to look atjava.awt.Color
, especially itsgetRGB()
method, which can convert Colors into integers that you can put into theint rgb
parameter ofsetRGB
.替代文本http://grab.by/grabs/39416148962d1da3de12bc0d95745341.png
alt text http://grab.by/grabs/39416148962d1da3de12bc0d95745341.png
今天我得到的另一点乐趣是,我使用 #Jave Cavas、Color、Graphics 和 #Swing JFrame 创建一个简单的着色像素类,我们所做的就是创建一个正方形的 JFrame 400×400 像素(框架需要很少的额外像素) self),然后我们扩展画布并对像素进行对称着色。
Another bit of fun I had today where I used #Jave Cavas, Color, Graphics and #Swing JFrame to create a simply colouring pixels class all we are doing is creating square a JFrame 400×400 pixels (few extra pixels required for the frame it self) and then we extend the Canvas and colour the pixels symmetrically.
您可以使用 java 的内置 2D Graphics 包来完成此操作。
You can accomplish this using java's builtin 2D Graphics package.