public class Object2D
/**
* A TwoD_Object contains two ints resembling its width and height,
* and a Color-Array constructed by them. That Array, contains the
* information about every possible point that could be used in the
* boundaries, set by int width and int height.
**/
{
int width;
int height;
Color PointInformation[][];
public void convertImageTo2DObject(BufferedImage image) {
this.width = image.getWidth();
this.height = image.getHeight();
this.PointInformation = new Color[width][height];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
this.PointInformation[row][col] = Color(image.getRGB(col, row));
}
}
}
我是在写一个类,它象征着一个2D对象。每个对象都有一个高度和一个宽度属性以及一个二维颜色 - 大小[宽度] [高度]的数组,它实际上包含由宽度和高度设置的边界内每个可能点的颜色。 到目前为止,我写了一些方法,正确地将简单的东西(如点或线)绘制到Object中,但现在我想将图片转换为我的2d-Object规范。
为此,首先计算导入BufferedImage的高度和宽度,
this.width = image.getWidth();
this.height = image.getHeight();
然后重新创建Object的PointInformation,将图像复制到。
this.PointInformation = new Color[width][height];
现在两个for循环遍历importet图片中的任何像素,
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
理论上将每个像素的RGB值转换为颜色,转换为对象PointInformation中的正确位置。
this.PointInformation[row][col] = Color(image.getRGB(col, row));
}
}
现在的问题是,Netbeans中的编译器告诉我:
Cannot find symbol
symbol: method Color(int)
location: class Object2D
所以它在这方面遇到了问题:
this.PointInformation = new Color[width][height];
但我不明白这是什么问题!我已经做了
import java.awt.Color;
import java.awt.image.BufferedImage;
(即使你在这里看不到它),我甚至试过
import java.awt.*;
但它也没有用,仍然告诉我它不知道那种方法。
我真的很感激,如果你能告诉我我做错了什么! 谢谢!