2
    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 对象。每个对象都有一个 height 和一个 width 属性以及一个大小为 [width][height] 的二维颜色数组,该数组实际上包含由 width 和 height 设置的边界内每个可能点的颜色。到目前为止,我写了一些方法,正确地将点或线等简单的东西绘制到对象中,但现在我想将图片转换为我的二维对象规范。

为此,首先计算importet BufferedImage 的高度和宽度,

this.width = image.getWidth();
this.height = image.getHeight();

然后是对象的 PointInformation 的重新创建,图像被复制到该对象上。

 this.PointInformation = new Color[width][height];

现在两个 for 循环在导入图片中的任何像素上运行,

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.*;

但它也没有用,仍然告诉我它不知道那种方法。

如果您能告诉我我做错了什么,我将不胜感激!谢谢!

4

0 回答 0