【发布时间】:2012-02-08 13:51:11
【问题描述】:
我有一个小问题,我想,不会很难。 但不知何故,我想念那个“不能太难”的部分:)。
我有一个代码,可以读取图像的颜色:
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);
//define the array size
rgbValues = new int[bmp.getWidth()][bmp.getHeight()];
//Print in LogCat's console each of one the RGB and alpha values from the 4 corners of the image
//Top Left
for (int j = 0; j < 1000; j++){
for (int k = 0; k < 1000; k++){
Log.i("Pixel Value", "pixel x="+j +k + Integer.toHexString(bmp.getPixel(j, k)));
test = Integer.toHexString(bmp.getPixel(j, k));
}
}
//get the ARGB value from each pixel of the image and store it into the array
for(int i=0; i < bmp.getWidth(); i++)
{
for(int j=0; j < bmp.getHeight(); j++)
{
//This is a great opportunity to filter the ARGB values
rgbValues[i][j] = bmp.getPixel(i, j);
}
}
System.out.println(PixelNumber);
System.out.println(test);
}
这段代码就像一个魅力。 但我试图实现一个 if 语句,如:
if (color == black){
number++;
}
所以他看到的每个像素都是黑色的,他必须将数字加1。
尝试了几乎所有我能想出的方法来围绕这段代码做一个好的 if 语句,但似乎没有任何效果。 那么在这段代码中正确的地方和 if 语句是什么?
也许如果您有更多时间(如果您不想要,请不要在这方面投入太多精力)是否可以检查颜色范围而不是仅检查一种颜色,因此它会选择所有绿色。 (与 Photoshop 中的颜色范围相同)。
【问题讨论】:
-
从描述中无法理解您在哪里尝试了 if 语句,但在您的其他代码中的任何地方都没有提到可变颜色。