Invert bitmap colors

Posted by Alex Orlov on Stack Overflow See other posts from Stack Overflow or by Alex Orlov
Published on 2011-01-07T10:23:23Z Indexed on 2011/01/07 12:53 UTC
Read the original article Hit count: 338

Filed under:
|
|

I have the following problem. I have a charting program, and it's design is black, but the charts (that I get from the server as images) are light (it actually uses only 5 colors: red, green, white, black and gray).

To fit with the design inversion does a good job, the only problem is that red and green are inverted also (green -> pink, red -> green).

Is there a way to invert everything except those 2 colors, or a way to repaint those colors after inversion? And how costly are those operations (since I get the chart updates pretty often)?

Thanks in advance :)

UPDATE

I tried replacing colors with setPixel method in a loop

for(int x = 0 ;x < chart.getWidth();x++) {
        for(int y = 0;y < chart.getHeight();y++) {
            final int replacement = getColorReplacement(chart.getPixel(x, y));
            if(replacement != 0) {
                chart.setPixel(x, y, replacement);
            }
        }
    }

Unfortunetely, the method takes too long (~650ms), is there a faster way to do it, and will setPixels() method work faster?

© Stack Overflow or respective owner

Related posts about java

Related posts about android