开发者

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

开发者 https://www.devze.com 2023-03-03 20:19 出处:网络
I draw some stuff on a canvas, over I want to draw a circle in inverted color : canvas.drawCircle(zx, zy, 8f, myPaint);

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 unde开发者_Go百科rlying pixels ?

Thanks


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);


I'd say a color matrix for inverting 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 information for the matrix:

0

精彩评论

暂无评论...
验证码 换一张
取 消