由网友(淡然回眸)分享简介:我做的,我要删除与事件画线的应用。为此,我使用I make an Application in which I want to erase drawing lines with event. For this I used mPaint.setXfermode(new PorterDuffXfermode(Port...
我做的,我要删除与事件画线的应用。为此,我使用
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);
}
}
相关推荐
最新文章