我正在使用下面的代码捕获绘图.为了更改笔触颜色或宽度,我调用了setPaintAttribute()方法.但是当我改变颜色时,整个绘图都会改变,包括我之前绘制的线条.如何更改颜料的颜色并保持以前的图纸不变?我试图创建一个新路径,但之前的绘图消失了.
public voID setPaintAttributes(float stroke_WIDTH,int color) { paint=new Paint(); paint.setAntiAlias(true); paint.setcolor(color); paint.setStyle(Paint.Style.stroke); paint.setstrokeJoin(Paint.Join.ROUND); paint.setstrokeWIDth(stroke_WIDTH); } public boolean ontouchEvent(MotionEvent event) { scrollVIEw.requestdisallowIntercepttouchEvent(true); btnSaveSignature.setEnabled(true); btnSaveSignature.setBackgroundResource(R.drawable.save); float eventX = event.getX(); float eventY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: path.moveto(eventX,eventY); lasttouchX = eventX; lasttouchY = eventY; return true; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: resetDirtyRect(eventX,eventY); int historySize = event.getHistorySize(); for (int i = 0; i < historySize; i++) { float historicalX = event.getHistoricalX(i); float historicalY = event.getHistoricalY(i); path.lineto(historicalX,historicalY); } path.lineto(eventX,eventY); break; } invalIDate((int) (dirtyRect.left - HALF_stroke_WIDTH),(int) (dirtyRect.top - HALF_stroke_WIDTH),(int) (dirtyRect.right + HALF_stroke_WIDTH),(int) (dirtyRect.bottom + HALF_stroke_WIDTH)); lasttouchX = eventX; lasttouchY = eventY; return true; } private voID resetDirtyRect(float eventX,float eventY) { dirtyRect.left = Math.min(lasttouchX,eventX); dirtyRect.right = Math.max(lasttouchX,eventX); dirtyRect.top = Math.min(lasttouchY,eventY); dirtyRect.bottom = Math.max(lasttouchY,eventY); }解决方法 创建一个包含路径和绘画对的arrayList,然后将每个路径添加到arrayList,它对我有用,
ArrayList<Pair<Path,Paint>> paths = new ArrayList<Pair<Path,Paint>>();
使用方法如下:
mCanvas = new Canvas(); mPath = new Path(); Paint newPaint = new Paint(mPaint); paths.add(new Pair<Path,Paint>(mPath,newPaint));总结
以上是内存溢出为你收集整理的android – 更改绘画颜色时,现有笔划也会更改全部内容,希望文章能够帮你解决android – 更改绘画颜色时,现有笔划也会更改所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)