我目前正在为我的“Java I”课程开展一个项目,该课程涉及图像过滤器和镜像。我正在尝试创建一个水平镜像效果(垂直镜像硬编码到java我相信),但当我尝试运行我的代码时,我收到消息:
错误:无法找到符号
表示我用注释标记的行。我最近得到了这个错误(在我正在处理的其他程序中),所以我确信我必须犯同样的错误。如果有人可以帮我解决这个问题,那将有助于我揭开编译错误的整个世界。
public static void testMirrorHorizontal()
{
Picture gorge = new Picture("gorge.jpg");
Pixel[][] pixels = gorge.getPixels2D();
Pixel topPixel = null;
Pixel bottomPixel = null;
int width = gorge.getWidth();
int length = pixels[0].width; // I'm getting the error here
for (int col = 0; col < pixels.length; col++)
{
for (int row = 0; row < height / 2; row++)
{
topPixel = pixels[row][col];
bottomPixel = pixels[col][height - 1 - row];
bottomPixel.setColor(bottomPixel.getColor());
}
}
}
答案 0 :(得分:5)
更改
int length = pixels[0].width;
到
int length = pixels[0].length;
pixels[index]
没有width
属性。
通过使用pixels[0].length
,您可以获得二维像素数组中第一个像素行中包含的像素数。