所以,我想要做的是通过一个图片是1024x768(或,popMap.getWidth x popMap.getHeight),抓住它的蓝色,比较它到目前为止最高的蓝色,如果它更多,那蓝色变成新的'newBlue'。基本上,找到图像中最高的蓝色值,最接近255蓝色。嵌套for循环存储到一个数组,只有一列嵌套循环到数组
此外,我试图将整个事情的蓝色值存储到一个数组popMapArray,这是一个3列2d数组,存储[blueValue] [x] [y]。然后,我将排序,以获得从高到低的蓝色值列表。
我的问题是,用下面的代码,它只是在列= 767时存储到数组中。
我得到1024 [蓝色,行,767],然后剩下的全是[0,0,0]
任何线索,为什么?顺便说一句,Java。
for (int row = 0; row < popMap.getWidth(); row++)
{
for (int column = 0; column < popMap.getHeight(); column++)
{
System.out.println(column);
//Find a Pixel
int c = popMap.getRGB(row, column);
int red = (c & 0x00ff0000) >> 16;
//int green = (c & 0x0000ff00) >> 8;
//int blue = c & 0x000000ff;
// and the Java Color is ...
Color color = new Color(red);
int newBlue = color.getBlue();
int oldBlue = lastColor.getBlue();
switch(popArrayRow)
{
case 0:
{
arrayVar = newBlue;
popArrayRow = 1;
break;
}
case 1:
{
arrayVar = row;
popArrayRow = 2;
break;
}
case 2:
{
arrayVar = column;
popArrayRow = 0;
break;
}
}
popArray[row][popArrayColumn] = arrayVar;
//System.out.println(popArray[row][popArrayColumn]);
switch(popArrayColumn)
{
case 0:
{
popArrayColumn = 1;
break;
}
case 1:
{
popArrayColumn = 2;
break;
}
case 2:
{
popArrayColumn = 0;
break;
}
}
if(newBlue > oldBlue)
{
startX = row;
startY = column;
//System.out.print(row);
//System.out.print(",");
//System.out.println(column);
System.out.print("The oldBlue is ");
System.out.println(oldBlue);
lastColor = color;
}
}
}
什么y?我不明白你的问题 – smas 2011-04-12 21:07:44
对不起,当列= 767. – 2011-04-12 21:10:31