如何给像素上色? [英] How to color a pixel?
问题描述
我必须创建一个简单的 2D 动画,而不能为此使用各种图元来绘制线、圆等.它必须通过操作像素并通过对像素着色来实现绘制线、圆等的算法之一来完成.
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.
为此我想过使用 Turbo C,但我使用的是 ubuntu.所以我尝试使用 dosbox 来安装和运行 turbo C 但无济于事.
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.
现在我唯一的选择是 Java.是否可以在 Java 中操作像素?我找不到任何相同的好教程.如果能给出相同的示例代码就太好了.
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.
推荐答案
java.awt.BufferedImage
有一个方法 setRGB(int x, int y, int rgb)
设置颜色单个像素.此外,您可能需要查看 java.awt.Color
,特别是它的getRGB()
方法,可以把Colors转换成整数,可以放入int rgb
参数中代码>setRGB.
The class java.awt.BufferedImage
has a method setRGB(int x, int y, int rgb)
which sets the color of an individual pixel. Additionally, you might want to look at java.awt.Color
, especially its getRGB()
method, which can convert Colors into integers that you can put into the int rgb
parameter of setRGB
.
这篇关于如何给像素上色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!