and welcome to my very first question on stackoverflow.com :)
I'm trying to invert specific colors of a Bitmap in Android app.
the idea is to have a night mode reading for kids story.
the story pages are colorful, including the text..
when I load the image in the normal mode; it will be displayed as is.
but when the user activates the night mode (press a button during reading) I want to invert the colors of the image.
BUT NOT all colors,,, only any black colored pixel to be inverted to white,,, and keep other colors as is,,,,
Following is an illustration of what I want to do (the upper part is inverting all colors,,, I want to achieve the lower part of the illustration): I used the following code,,, but still anti-aliased black pixels are not inverted very well!!
//Code snipet
Bitmap copy = myBitmap.copy(myBitmap.getConfig(), true);
int length = copy.getWidth() * copy.getHeight();
int[] array = new int[length];
copy.getPixels(array,0,copy.getWidth(),0,0,copy.getWidth(),copy.getHeight());
for (int i=0;i<length-(length/10);i++){
//trying to overcome text anti-aliasing
if ( (array[i] & 0x00FFFFFF) <= 0x00222222)
{
array[i] = 0xffffffff;
}
}
copy.setPixels(array,0,copy.getWidth(),0,0,copy.getWidth(),copy.getHeight());
The ACTUAL sample image i want to invert its colors
If there is a solution using the setColorFilter(ColorMatrixColorFilter(float[])) it would be perfect! – Loay Jan 17 '15 at 12:26