【问题标题】:How to code for the eraser as like paint in android canvas?如何为橡皮擦编码,就像在 android 画布中绘画一样?
【发布时间】:2011-12-24 08:10:57
【问题描述】:

在我的绘图应用程序中,我正在使用以下代码在画布上进行绘画:

currentPaint = new Paint();
            currentPaint.setDither(true);
            currentPaint.setColor(0x00000000);
            currentPaint.setStyle(Paint.Style.STROKE);
            currentPaint.setStrokeJoin(Paint.Join.ROUND);
            currentPaint.setStrokeCap(Paint.Cap.ROUND);
            //currentPaint.setStrokeWidth(3);

不,我想像油漆一样实现橡皮擦。 可以在画布上做吗?如果是,请帮助我。

谢谢。

【问题讨论】:

    标签: android android-layout android-emulator android-widget android-canvas


    【解决方案1】:
      currentPaint.setAlpha(0xFF);
      currentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    

    致电invalidate 即可刷新抽奖。

    【讨论】:

      【解决方案2】:

      您可以使用背景颜色创建图形对象。然后看起来对象后面的东西都被删除了。

      【讨论】:

      • 我没有正确理解你。有没有像你说的那样的例子?
      • 只需将油漆的颜色设置为画布的背景颜色即可。然后这幅画看起来像被擦除了。
      • 请给它一些代码好吗?我不知道如何做到这一点。
      • 好吧,Stackoverflow 不是一个让人们为您工作的网站。对不起。
      猜你喜欢
      • 2011-12-30
      • 2011-04-16
      • 2019-01-30
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      相关资源
      最近更新 更多