不兼容的类型:RGBColor [] []无法转换为Double [] [] -Error

时间:2018-11-13 08:21:01

标签: java arrays double tostring rgbcolor

在使我发疯的事情上,我需要一些帮助。 有关代码的一些信息-

  1. 像素是红色,绿色和蓝色3种颜色。
  2. RGBColor [] []代表像素数组。
  3. RGBImage [] []表示RGBColor的数组。 RGBImage [] []数组的每个单元格中都有一个RGBColor对象。
  4. convertToGrayscale()是一种将每个像素转换为其灰度值的方法。
  5. 还有RGBImage类的toString()方法,该方法将打印出具有所有值的图像-RGBColor对象的数组。

问题-我希望toGrayscaleArray()方法使用convertToGrayscale()方法。因此,我建立了一个for循环,将数组的每个单元格转换为灰度。但是当我尝试返回现在已转换的_rgbimage时,出现编译器错误- 不兼容的类型:RGBColor [] []无法转换为Double [] []

任何帮助将不胜感激。

    /** returns grayscale representation of the image
    * @return grayscale representation of the image
    */
    public double [][] toGrayscaleArray()
    {
    int row = _rgbimage.length;
    int col = _rgbimage[0].length;

    for (int i = 0; i < row; i++)
        for (int j = 0; j < col; j++)
        {
            _rgbimage[i][j].convertToGrayscale();

        } 
    return _rgbimage; //THE COMPILER ERROR IS HERE
}

toString()-该方法已经过测试,可以正常工作。

/** creates a string of matrix which represents the image, in the following format:
 * (red,green,blue) (red,green,blue) (red,green,blue)
 * (red,green,blue) (red,green,blue) (red,green,blue)
 * (red,green,blue) (red,green,blue) (red,green,blue)
 * @return toString
 */
public String toString ()
{
    int rows = _rgbimage.length; 
    int cols = _rgbimage[0].length;
    String imageMatrix = new String("");
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            if (j < cols-1) //checks if it's the last cell on the row
                imageMatrix += _rgbimage[i][j] + " "; //if not last cell - add space
            else 
                imageMatrix += _rgbimage[i][j]; //if last cell - don't add space             
        }
        imageMatrix += "\n";
    }
    return imageMatrix;
    }

0 个答案:

没有答案
相关问题