如何更改默认的擦除颜色在涂料中的应用在Android中? [英] How to change default erase color in paint application in Android?
问题描述
我做的,我要删除与事件画线的应用。为此,我使用
I make an Application in which I want to erase drawing lines with event. For this I used
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
但删除一行时,该行成为黑先擦除。我希望有一个透明的颜色擦除绘制路径。
but at the time of erasing a line, that line becomes black first then erased. I want a transparent color for erasing a drawing a path.
推荐答案
以下适用于消除在一个透明的背景...
The below works for erasing on a transparent background...
呼叫SetErase(真)开始擦除。
Call SetErase(true) to start erasing.
在OnDraw的方法再画一个白色的路径(而不是黑色),这将随后得到清除,以透明色,你把所有的路撤销信息。
The OnDraw method will then draw a white path (instead of black)which will then get cleared to the transparent color and you keep all your path undo info.
呼叫SetErase()来切换消除开/关
Call SetErase() to toggle erasing on/off
public void SetErase(bool On)
{
if (On)
{
if (!_erasing)
{
_delpaint = new Paint(_paint);
_delpaint.Color = Color.White;
_paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Clear));
_erasing = true;
}
}
else if (_erasing)
{
_erasing = false;
_paint.SetXfermode(null);
}
}
protected override void OnDraw(Canvas canvas)
{
canvas.DrawColor(BackgroundColor);
canvas.DrawBitmap(CanvasBitmap, 0, 0, _bitmapPaint);
if (_erasing)
{
canvas.DrawPath(_path, _delpaint); // draw white path
}
else
{
canvas.DrawPath(_path, _paint);
}
}
这篇关于如何更改默认的擦除颜色在涂料中的应用在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!