Android 洪水填充说明

Android 洪水填充说明,android,queue,flood-fill,Android,Queue,Flood Fill,我正在处理我的具有绘画/着色功能的项目。有人能解释一下这种泛洪填充算法以及它是如何工作的吗?这是洪水排队吗?(在这个算法中)队列意味着什么 公共级洪水填筑{ 公共空白泛光填充(位图图像、点节点、int targetColor、, int replacementColor){ int width=image.getWidth(); int height=image.getHeight(); int target=targetColor; int replacement=replacementCol

我正在处理我的具有绘画/着色功能的项目。有人能解释一下这种泛洪填充算法以及它是如何工作的吗?这是洪水排队吗?(在这个算法中)队列意味着什么

公共级洪水填筑{
公共空白泛光填充(位图图像、点节点、int targetColor、,
int replacementColor){
int width=image.getWidth();
int height=image.getHeight();
int target=targetColor;
int replacement=replacementColor;
如果(目标!=更换){
Queue Queue=new LinkedList();
做{
int x=node.x;
int y=node.y;
而(x>0&&image.getPixel(x-1,y)=目标){
x--;
}
布尔spanUp=false;
布尔值=假;
而(x0
&&image.getPixel(x,y-1)=目标){
添加(新点(x,y-1));
spanUp=true;
}如果(spanUp&&y>0),则为else
&&image.getPixel(x,y-1)!=目标){
spanUp=false;
}
如果(!spanDown&&y<高度-1
&&image.getPixel(x,y+1)=目标){
添加(新点(x,y+1));
spanDown=true;
}否则,如果(向下和向下<高度-1
&&image.getPixel(x,y+1)!=目标){
spanDown=false;
}
x++;
}
}而((node=queue.poll())!=null);
}
}
}

此算法没有特定名称,但在填充大面积区域时,我建议使用排队线性洪水填充算法,该算法比上述算法快得多

以下是实现的链接:


您想知道什么?目前,您正在根据屏幕上的位置和颜色绘制位图。好的,您的威斯汀酒店具体是什么?您可以分别让他们看一下项目符号吗?我想知道使用的是哪种洪水填充。
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);
        }
    }
}