所以,我想要做的是通過一個圖片是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