I'm working on Bitmap images in Android Studio, and I would know how to do to detect all red pixels for examples, but not just the pixels that are strictly equals to Color.RED. I just give an example with RED color, but I want to do it with all different color possible.
I tried to do this:
...
int[] pixels = new int[width * height];
myBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < width * height; i++) {
if (pixels[i] == Color.RED) {
// color detected
}
...
But this doesn't work as my image does not contains red pixel that is (255, 0, 0) but contains pixels that could be (251, 30, 77) or (239, 23, 42), which is also "red", etc...
So how could I do to such thing ? I also tried something like :
int reference; // color as rgb
if ( (Color.red(pixels[i]) > Color.red(reference) - 20) &&
(Color.red(pixels[i]) < Color.red(reference) + 20 &&
...
{
// pixel detected
}
...
Where I suppose that (r +- 20, g +- 20, b +-20) is part of (r, g, b) (I mean, for human eye)
Any idea on how I can do that ?