How to draw with inverted paint in Android canvas?

I draw some material on the canvas, I want to draw a circle in an inverted color:

canvas.drawCircle(zx, zy, 8f, myPaint); 

How to set myPaint for a district pixel to the inverted color of the base pixels?

thanks

+7
source share
3 answers

try it

 float mx [] = { -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, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f }; ColorMatrix cm = new ColorMatrix(mx); p.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.drawCircle(zx, zy, 8f, p); 
+4
source

I would say that the color matrix for inversion should look like this:

 float mx [] = { -1.0f, 0.0f, 0.0f, 0.0f, 255.0f, 0.0f, -1.0f, 0.0f, 0.0f, 255.0f, 0.0f, 0.0f, -1.0f, 0.0f, 255.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; 

Here is more info for the matrix:

+3
source
 myPaint.setColor(Integer.MAX_VALUE - color); 
-3
source

All Articles