洪水填充和RGB值

时间:2013-06-27 08:31:38

标签: c++ visual-c++

我正在编写一个填充方法来填充红色的图像(狗的轮廓)。

在我的TestShellDlg.cpp中是泛洪填充方法。 CTestShellDlg :: m_pScreenDib成员是一个CDIB32位图类,它包含图形并绘制它们。

我想对当前像素进行采样,如果它不是黑色(轮廓的颜色),则将其染成红色。这是Dib32.cpp类中的getter:

void CDIB32::GetRGB(int x, int y, BYTE& r, BYTE& g, BYTE& b)
{
    if (x >= Width() || y >= Height())
        IERROR;

    int off = y * ByteWid() + x * 4;
    b = m_pBits[off];
    g = m_pBits[off+1];
    r = m_pBits[off+2];
}

这是我在TestShellDlg.cpp类中的floodfill方法:

void CTestShellDlg::FloodFill(CPoint& mid)
{

    //while the current pixel colour is not black, set it to red and recursively loop
    m_pScreenDib ->GetRGB(mid.x,mid.y, (byte)& r,(byte)& g,(byte)& b);
        while(r !=(byte)0, g !=(byte)0, b !=(byte)0)
        {
            m_pScreenDib -> SetRGB(mid.x, mid.y,(byte)255,(byte) 0,(byte) 0);
            mid.x++;
            FloodFill(mid);
            mid.x--;
            FloodFill(mid);
            mid.y++;
            FloodFill(mid);
            mid.y--;
            FloodFill(mid);
        }

}

问题是,它是说r,g,b是未定义的。我不知道为什么。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您需要在使用它们之前声明(您不能在参数列表中将它们声明为内联)

byte r,g,b;
m_pScreenDib ->GetRGB(mid.x,mid.y, (byte)& r,(byte)& g,(byte)& b);