我得到了一个小问题,我认为,不难。但是不知何故,我想念“不可能很难”的一部分:)。如何使用颜色代码声明
我有一个代码,读取图像的颜色:
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
几乎尝试了我能想出了做一个好一切的数量如果围绕此代码声明,但似乎没有任何工作。 那么这个代码中的正确位置和声明是什么?
也许如果你有更多的时间(不要放太多精力在这,如果你不想要的)是有可能只是代替1种颜色检查色彩范围,所以它选择所有的绿色。 (与Photoshop中的颜色范围相同)。
从描述它无法理解你已经尝试了if语句,不存在一提您的其他代码中的任 – 2012-02-08 14:02:16