在使我发疯的事情上,我需要一些帮助。 有关代码的一些信息-
问题-我希望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;
}