如何实现在Android的绘图应用橡皮擦 [英] How to implement an eraser for a drawing app in Android

查看:536
本文介绍了如何实现在Android的绘图应用橡皮擦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一些方法来实现对我的绘画应用程序的橡皮擦功能的所有夜晚。最常见的答案是简单地画在背景颜色或图像,而是因为我实现多层该解决方案将不会为我的应用程序工作(GIMP / Photoshop的样式)。

I have been searching all evening for some way to implement an eraser function for my drawing app. The most common answer is to simply paint the background color or image in, but this solution will not work for my application because I am implementing multiple layers (Gimp/Photoshop style).

用户应该能够得出一个符合作为多层次提供他们喜欢的笔刷工具(我drawingview的的onDraw方法绘制layer0 ... layerX在彼此的顶部)。当然,如果他们选择橡皮擦工具,应该引起他们追查到变得透明当前层的任何区域。

The user should be able to draw a line with the brush tools provided in as many layers as they like (the onDraw method of my drawingview draws layer0...layerX on top of each other). Then if they choose the eraser tool it should cause any area of the current layer that they trace over to become transparent.

我似乎无法找到一个合适的类/函数内置的,我不能确定我如何写我自己。我试图做类似

I cannot seem to find an appropriate class/function built in and am unsure how I could write it myself. I tried to do something like

Paint paint = new Paint();
paint.setAlpha(0);

,然后使用该画图对象,绘制,但只绘制了一个无形线。

and then use that Paint object to draw with, but that only draws an 'invisible' line.

我也尝试使用

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

但只是似乎画正常的和没有效力。我可能用它不正确,但Android文档不包含它做什么明确的说明。我刚好看到它在一些例子有关修改位图。

but that just seemed to draw as normal and without effect. I'm probably using it incorrectly, but the Android documentation does not contain a clear description of what it does. I just happened to see it in some examples about modifying bitmaps.

我能提供code可以根据需要,我只是不知道什么将有助于解决我的问题。被指出了正确的方向将是最大的帮助,因为我还没有成功的谷歌。

I can supply code as needed, I am just not sure what would be helpful to solve my problem. Being pointed in the right direction would be the biggest help as I have not been successful with Google.

推荐答案

您可以找到橡皮擦功能的实现,创造新的画布,画笔功能和保存功能,此链接:

You can find the implementation of eraser function, create new canvas, brush function and save function, on this link :

<一个href=\"http://mobile.tutsplus.com/tutorials/android/android-sdk-create-a-drawing-app-interface-creation/\"相对=nofollow>创建Android的绘图介面

这是有非常好的教程制作Android上使用运动事件绘图应用程序。

it's have very good tutorial for making drawing app on android using motion event.

这篇关于如何实现在Android的绘图应用橡皮擦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆