I have a code that turns a bitmap that has the grey colors into a bitmap of black and white colors, using this code:
// scan through all pixels
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
// get pixel color
pixel = bitmap.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
int gray = (int) (0.2989 * R + 0.5870 * G + 0.1140 * B);
// use 128 as threshold, above -> white, below -> black
if (gray > 128)
gray = 255;
else
gray = 0;
// set new pixel color to output bitmap
bmOut.setPixel(x, y, Color.argb(A, gray, gray, gray));
}
}
As you can see I travel all the pixels points of the original bitmap and then I compare the components of the color with a given threshold, in this case 128, and then if its above I say its white otherwise it will be a black pixel.
What I want to do now, is a Spinner that can change that threshold value, and then the BW image will be different.
To do this, I would need to draw all the image again, and that is very cpu costing time, its takes time to travel all the pixels again.
Is therey any way to change the image using a different BW threshold in real-time?
Someone told me to use a GIF, and then what I would do, was just changing the lookup table values of the GIF, does anyone has knowledge about this on Android?