Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw with an "inverted" paint in Android Canvas?

I draw some stuff on a canvas, over I want to draw a circle in inverted color :

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

How to configure myPaint for circle pixel to be in the inverted color of the underlying pixels ?

Thanks

like image 503
Nicolas Avatar asked May 09 '11 20:05

Nicolas


1 Answers

try this

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);
like image 139
George Avatar answered Jan 02 '23 06:01

George