此时,floodFill implementetion [英] Floodfill implementetion

查看:101
本文介绍了此时,floodFill implementetion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的颜色填充功能的问题:

I have a problem with my flood fill function:

void floodfill(int x, int y,Pixel old, Pixel new){

Pixel current = getPixel(x,y);

if(current.r == old.r && current.g == old.g && current.b == old.b){

    setPixel(x,y,new);

    floodfill(x+1,y,old,new);
    floodfill(x-1,y,old,new);
    floodfill(x,y+1,old,new);
    floodfill(x,y-1,old,new);
    floodfill(x+1,y+1,old,new);
    floodfill(x-1,y-1,old,new);
    floodfill(x+1,y+1,old,new);
    floodfill(x-1,y+1,old,new);
}
}

在结构'像素'我有像素的RGB值。我想,以填补一个正方形,当我来到了广场上的边框(从白到黑的颜色变化,边界点x = 200处),该功能是在不改变其它像素只是无休止地更改x值198和199(没关系的y值)。谁能告诉我什么,我做错了什么?

In struct 'Pixel' I have rgb values of the pixel. I am trying to fill a square and when I come to the border of the square (color changes from white to black, the border is at point x=200) the function is not changing to other pixels but just endlessly changing the x value to 198 and 199 (nevermind the y value). Can someone tell me what I am doing wrong?

推荐答案

这听起来像setPixel未设定(X,Y)的颜色与新。那么,发生了什么是递归调用顺序如下:

This sounds like setPixel isn't setting the colour of (x,y) to the "new". So, what's happening is the following sequence of recursive calls:

(199,Y) - >(200,Y)[本停止,因为边界不具有相同的颜色作为旧]         - >(198,Y) - >(199,Y)[(199,Y)获取调用,因为setPixel可能​​没有改变的颜色(199,Y)] - > ...

(199,y)->(200,y) [This stops because the border doesn't have the same colour as old] ->(198, y)->(199,y) [(199, y) is getting called because setPixel likely didn't change the colour of (199, y)]->...

这篇关于此时,floodFill implementetion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆