如何在android.But中实现洪水填充算法,代码是用c language.could编写的,我们在android.is中实现了算法,有任何开源代码或任何网站教程链接。
发布于 2012-03-09 06:00:54
洪水填充算法是一种非常简单的递归算法。
//Initialize i and j to the place to start
floodFill(int arr[][], target_color, replace_color)
{
if(arr[i][j] == replace_color)
return;
replace(target_color, replace_color);
floodFill(int[i+1][j], target_color, replace_color);
floodFill(int[i][j+1], target_color, replace_color);
floodFill(int[i-1][j], target_color, replace_color);
floodFill(int[i][j-1], target_color, replace_color);
}使用队列进行洪水填充。使用异步任务来填充。
参数
要填充的
公共类FloodFill {公共空floodFill(Bitmap图像、点节点、int targetColor、int replacementColor) { int宽度= image.getWidth();int高度= image.getHeight();int目标= targetColor;int替换= replacementColor;if (target !=替换){ Queue queue =新LinkedList();do { int x= node.x;int y= node.y;时间(x >0& image.getPixel(x - 1,y) ==目标){x-;}布尔spanUp = false;布尔spanDown = false;while (x <宽度& image.getPixel(x,y) ==目标){ image.setPixel(x,y,置换);如果(!spanUp &y>0 && image.getPixel(x,y-1) ==目标){queue.add(新点(x,y- 1));spanUp = true;} if (spanUp &y>0& image.getPixel(x,y- 1) != image.getPixel){ spanUp = false;}如果(!spanDown &y&y }
https://stackoverflow.com/questions/9629530
复制相似问题