I got a little problem, what I think, can’t be hard.
but somehow, I miss that “can’t be hard” part :).
I got a code, that reads the colors of an image:
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);
}
This code works like a charm.
But I tried to implement an if statement like:
if (color == black){
number++;
}
So every pixels he sees that is black, he must increase the number with 1.
Tried almost everything I could came up to make a good if statement around this code, but nothing seems to work.
So what is the correct place and if statement to make in this code?
And maybe if you got more time (do not put too much effort in this if you don’t want) is it possible to check on a color-range instead of 1 color only, So it picks all green colors. (same as Color range in photoshop).
getPixel returns the 4bytes of ARGB in an integer. What you should do is to compose the color you want to count (the argb method of Color will help you) and test on this value with
getPixel(x, y).For black this will be easy:
For ranges you can use the
green/red/bluemethods, each returning the value of that component. If it is non-zero, the pixel has color from that component.