大佬教程收集整理的这篇文章主要介绍了android – 填充完整的画布,但保持绑定的填充区域,因为它像圆形,矩形,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
你好朋友,
我创建绘画应用程序,我有问题.如果我绘制没有填充的矩形和/或其他类似绑定区域并更改背景颜色,则矩形填充区域也会更改意味着整个画布颜色将填充新的背景颜色.如何保持背景或填充未绑定的画布区域,这是图像
这是初始图像
更改背景颜色后获得此结果
但是如何变成这样的方式
final Point p1 = new Point(); p1.x=(int) x; //x co-ordinate where the user touches on the screen p1.y=(int) y; //y co-ordinate where the user touches on the screen new TheTask(yourbitmap,p1,sourceColor,targetColor).execute();// use asyntask for efficiency class TheTask extends AsyncTask<Void,Integer,Void> { Bitmap bmp; Point pt; int replacementColor,targetColor; ProgressDialog pd; public TheTask(Bitmap bm,Point p,int sc,int tC) { this.bR_823_11845@p=bm; this.pt=p; this.replacementColor=tc; this.targetColor=sc; pd= new ProgressDialog(co@R_607_10443@t); pd.setmessage("Filling...."); } @Override protected void onPreExecute() { pd.show(); } @Override protected void onProgressupdate(Integer... values) { } @Override protected Void doInBACkground(Void... params) { FloodFill f= new FloodFill(); f.floodFill(bmp,pt,targetColor,replacementColor); return null; } @Override protected void onPostExecute(Void result) { pd.dismiss(); invalidate(); }
最后使用FloodFill算法填充封闭区域
public class FloodFill { public void floodFill(Bitmap image,Point node,int targetColor,int replacementColor) { int width = image.getWidth(); int height = image.getHeight(); int target = targetColor; int replacement = replacementColor; if (target != replacement) { Queue<Point> queue = new LinkedList<Point>(); do { int x = node.x; int y = node.y; while (x > 0 && image.getPixel(x - 1,y) == target) { x--; } Boolean spanUp = false; Boolean spanDown = false; while (x < width && image.getPixel(x,y) == target) { image.setPixel(x,y,replacement); if (!spanUp && y > 0 && image.getPixel(x,y - 1) == target) { queue.add(new Point(x,y - 1)); spanUp = true; } else if (spanUp && y > 0 && image.getPixel(x,y - 1) != target) { spanUp = false; } if (!spanDown && y < height - 1 && image.getPixel(x,y + 1) == target) { queue.add(new Point(x,y + 1)); spanDown = true; } else if (spanDown && y < height - 1 && image.getPixel(x,y + 1) != target) { spanDown = false; } x++; } } while ((node = queue.poll()) != null); } } }
以上是大佬教程为你收集整理的android – 填充完整的画布,但保持绑定的填充区域,因为它像圆形,矩形全部内容,希望文章能够帮你解决android – 填充完整的画布,但保持绑定的填充区域,因为它像圆形,矩形所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。