Java Android绘画应用程序撤销路径
我在绘画应用程序上遇到了一些问题。我扩展了View类,高估了一些主要方法。以下是一些: 变量:Java Android绘画应用程序撤销路径,java,android,path,paint,Java,Android,Path,Paint,我在绘画应用程序上遇到了一些问题。我扩展了View类,高估了一些主要方法。以下是一些: 变量: private ArrayList<Path> aldrawPath; private ArrayList<Paint> aldrawPaint; -绘图矩形 Draw a white rectangle where the user will paint drawCanvas.drawRect(left,top,right,bottom,myPaint); -火山口 1
private ArrayList<Path> aldrawPath;
private ArrayList<Paint> aldrawPaint;
-绘图矩形
Draw a white rectangle where the user will paint
drawCanvas.drawRect(left,top,right,bottom,myPaint);
-火山口
1.Action down --> path.moveTo
2.Action move --> path.lineTo
3.Action up --> path.drawpath + path and paint added to their arrays + path.reset
-调整大小
*everything as a normal resize +
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
问题:
当我单击“撤消”按钮时,理论上添加的最后一个绘制路径将被删除,它必须在画布上绘制路径.size()-1
它的作用:它只是画一个白色的长方形。永远不要走小路
如果您需要更多的代码或要求任何东西,请随时这样做
提前谢谢
解决方案:
问题出在那件事上。您不应使用path.reset(),而应使用:
路径=新路径() 您是否在
onDraw()
中检查(使用日志记录)了相应数组的大小?另外,我很确定您不想修改OnDraw()
中的路径列表,因为这样做效率非常低。另外,尝试使用foreach循环,您当前正在大声呼叫off by one errors.hi!我已经将一些代码移到了功能备份中,以便修改那里的路径(我现在要编辑我的帖子)。我已经在onDraw中记录了各个数组的大小,并且似乎是正确的(每次单击“撤消”按钮时,它都会将1减为大小…)让我猜猜:path.reset()
Wow!这很有效,非常感谢,我现在将编辑帖子,添加固定代码。你应该能够回答你自己的问题。请这样做,因为这样可以了解问题是如何解决的。
1.Action down --> path.moveTo
2.Action move --> path.lineTo
3.Action up --> path.drawpath + path and paint added to their arrays + path.reset
*everything as a normal resize +
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);