我得到了一個小問題,我認爲,不難。但是不知何故,我想念「不可能很難」的一部分:)。如何使用顏色代碼聲明
我有一個代碼,讀取圖像的顏色:
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