我使用位图绘制选项,每个路径都有一个唯一的颜色但撤消,重做不起作用..
这是我的bitmappaint代码:
public MyVIEw(Context context,Object object) { super(context); setFocusable(true); setFocusableIntouchMode(true); mPath = new Path(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setcolor(0xFFFFFF00); mPaint.setStyle(Paint.Style.stroke); mPaint.setstrokeJoin(Paint.Join.ROUND); mPaint.setstrokeCap(Paint.Cap.ROUND); mPaint.setstrokeWIDth(3); mBitmap = Bitmap.createBitmap(320,480,Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap);}protected voID onSizeChanged(int w,int h,int olDW,int oldh) { super.onSizeChanged(w,h,olDW,oldh);}protected voID onDraw(Canvas canvas) { canvas.drawBitmap(mBitmap,mBitmapPaint); for (Path p : paths) { canvas.drawPath(p,mPaint); } canvas.drawPath(mPath,mPaint);}public boolean ontouchEvent(MotionEvent event){ float x = event.getX(); float y = event.getY(); int action = event.getAction(); int action1=event.getAction(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: undonePaths.clear(); mPath.reset(); mPath.moveto(x,y); mX = x; mY = y; startPoint = new PointF(event.getX(),event.getY()); endPoint = new PointF(); invalIDate(); // isDrawing = true; break; case MotionEvent.ACTION_MOVE: float dx = Math.abs(x - mX); System.out.println("action move"); float dy = Math.abs(y - mY); if (dx >= touch_TolERANCE || dy >= touch_TolERANCE) { // currentDrawingPath.path.quadTo(mX,mY,(x + mX)/2,(y + mY)/2); } mX = x; mY = y; endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = true; invalIDate(); break; case MotionEvent.ACTION_UP: mPath.lineto(mX,mY); paths.add(mPath); mPath = new Path(); // mCanvas.drawPath(mPath,ppaint); endPoint.x = event.getX(); endPoint.y = event.getY(); isDrawing = false; invalIDate(); break; default: break; } }
![bitmappaint canvas的输出] [1]
[1]:http://i.stack.imgur.com/9aQvE.png
没有位图使用我遇到颜色问题,如果我为路径选择蓝色意味着所有以前的路径将改为蓝色;
这是我的代码
protected voID onDraw(Canvas canvas) { canvas.drawBitmap(mBitmap,mPaint);}
![使用画布绘制无位图的输出] [2]
[2]:http://i.stack.imgur.com/eDp5Y.png
请帮我在androID中绘制具有不同颜色的独特路径的多条路径.
谢谢advancde ……..
case MotionEvent.ACTION_UP: paths.add(mPath); colorsMap.put(mPath,selectedcolor); // store the color of mPath ...
在绘制路径之前,您需要设置绘制颜色:
protected voID onDraw(Canvas canvas) { canvas.drawBitmap(mBitmap,mBitmapPaint); for (Path p : paths) { mPaint.setcolor(colorsMap.get(p)); canvas.drawPath(p,mPaint); } mPaint.setcolor(selectedcolor); canvas.drawPath(mPath,mPaint);}
而colorsMap是一个简单的实例变量:
private Map<Path,Integer> colorsMap = new HashMap<Path,Integer>();
要实现撤消/重做功能,您只需从路径中删除最后一个元素(并将其存储在undoneList中,以便重做时可以恢复它).见Android Canvas Redo and Undo Operation
总结以上是内存溢出为你收集整理的如何绘制不同颜色的多行并撤消,重做android中的路径?全部内容,希望文章能够帮你解决如何绘制不同颜色的多行并撤消,重做android中的路径?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)