You can use a ColorMatrix in your paint brush to translate the RGBA
values of your image.

Here is a way of changing the hue 180 degrees (inverting "color
only"), but preserving lightness and saturation:

Canvas c = new Canvas(destBitmap);
Paint p = new Paint();
float[] mx = {
 0.0f,  0.5f,  0.5f,  0.0f,  0.0f,
 0.5f,  0.0f,  0.5f,  0.0f,  0.0f,
 0.5f,  0.5f,  0.0f,  0.0f,  0.0f,
 0.0f,  0.0f,  0.0f,  1.0f,  0.0f
};
ColorMatrix cm = new ColorMatrix(mx);
p.setColorFilter(new ColorMatrixColorFilter(cm));
c.drawBitmap(srcBitmap, 0, 0, p);


If you literally want to "invert" the bits, and make each RGB value
equal to 255 minus its original value, then the matrix would look
something like this:
float[] mx = {
 -1.0f,  0.0f,  0.0f,  0.0f,  1.0f,
 0.0f,  -1.0f,  0.0f,  0.0f,  1.0f,
 0.0f,  0.0f,  -1.0f,  0.0f,  1.0f,
 0.0f,  0.0f,  0.0f,  1.0f,  0.0f
};

I didn't test this. Check out the ColorMatrix class docs.

-broc


On Jul 17, 7:48 pm, efu <ericf...@gmail.com> wrote:
> I have a Canvas backed by a bitmap that I want to invert the color for
> a rectangular region.
> The meaning of inversion is to flip the bits of all the colors pixels.
>
> I can't seem to find an easy way to do it using the Paint class.
> Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to