在 Android FingerPaint 演示中如何删除绘制的路径
我一直在尝试更改 Android (v3.0 Honeycomb) API 演示 FingerPaint (API >= 11) 以包含一个可删除最后绘制路径的工作擦除选项。
API 演示中的擦除效果不佳,在 v3.0 中会崩溃,在 v3.1 中会绘制一个黑框,而仅部分擦除路径(已提出一个错误,不确定是否已在 v3.2 中解决[不适用于英国的 Xoom 设备])。
我的代码如下:
public void eraseLastPath() {
if (!mPaths.isEmpty()) {
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mCanvas.drawPath(mPaths.pop(), mPaint);
invalidate();
}
}
这有点有效,但会在画布上留下绘制路径的轮廓。例如
这个:
被删除,如下所示:
我缺少什么?有没有更好的方法来删除路径?
非常感谢任何帮助。
谢谢
乔
I've been trying to alter the Android (v3.0 Honeycomb) API Demo FingerPaint (API >= 11) to include a working erase option that removes the last drawn path.
The erase in the API demo doesnt work well, in v3.0 is crashes, in v3.1 is draws a black box while only partially erasing the path (a bug has been raised not sure if it has been resolved in v3.2 [not out for Xoom device in UK]).
My code is as follows:
public void eraseLastPath() {
if (!mPaths.isEmpty()) {
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mCanvas.drawPath(mPaths.pop(), mPaint);
invalidate();
}
}
This somewhat works but leaves an outline of the drawn path on the canvas. e.g.
this:
is erased to look like this:
What am I missing? Is there a better way to erase paths?
Any help is much appreciated.
Thanks
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 mPaint 抗锯齿设置为打开。
编辑:
擦除路径的正确方法是将所有笔划存储到 ArrayList 中,然后删除不需要的笔划并重新绘制所有内容。问题中使用的方法并不是真正删除路径,而更像是在其上绘制另一种颜色,但是抗锯齿的工作方式与使用第一种颜色的方式不同。
每个路径都需要是新类“笔划”中的成员对象,该类还存储了颜色、绘画、滤镜等。通过这种方式,所有绘图都可以恢复,并且可以无限撤消。
Try to set mPaint anti-alias on.
Edit:
The proper way to erase a path is to store all strokes into an ArrayList and then remove the unwanted one and redraw everything. The method used in the question is not really deleting a path but more like drawing another colour over it, but then anti-alias would not work the same as with the first colour.
Each path needs to be a member object in a new class "stroke", which also has colour, paint, filters etc stored. In this way all drawing can be restored and it can have infinite undo.
单独保存最后绘制的
Path
(不绘制到Bitmap
上)进行绘制。这允许您在将路径提交到支持位图
之前对其进行操作。例如:
注意:该示例不允许使用多种颜色。您只需扩展
Path
对象并在其上保存颜色信息(并相应地设置Paint
)。另外,如果您将其与 Honeycomb 设备一起使用,请确保使用
android:hardwareAccelerated="true"
打开硬件加速。Hold the last drawn
Path
(s) separately (not drawn ontoBitmap
) for drawing. This allows you to manipulate thePath
s before committing them to a backingBitmap
.For example:
Note: The example doesn't allow for multiple colours. You can just extend the
Path
object and hold colour information on it (and set thePaint
accordingly).Also, if you are using this with a Honeycomb device, make sure you have hardware acceleration turned on with
android:hardwareAccelerated="true"
.