Android Paint PorterDuff.Mode.CLEAR drawing black color on my view

岁酱吖の 提交于 2019-12-06 07:06:42

Try the below code.

      paint.setAlpha(0xFF);//transperent color
      paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));//clear the draw

Also have a look at the sample FingerPaint.java in the api demos under the folder graphics.

 setAlpha(int a)

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

http://developer.android.com/reference/android/graphics/Paint.html. Have a look a the documentation.

Edit:

Also check this

https://code.google.com/p/android/issues/detail?id=54105#c1

I had same issue.

Need to set view's setLayerType.

yourView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

You can set it in constructor or by view's object.

Its done.

This is should resolve this issue

private void touch_move(float x, float y){
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);

        mPath.lineTo(mX, mY);
        mCanvas.drawPath(mPath, mPaint);
        mPath.reset();
        mPath.moveTo(mX, mY);

        mX = x;
        mY = y;
    }
}

in touch_up() change it to:

private void touch_up() {

     mPath.reset();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!