2013-06-27 76 views
0

我正在寫一個洪水填充方法來填充圖像(狗的輪廓)與紅色。洪水填充獲取和RGB值

在我的TestShellDlg.cpp是洪水填充方法。 CTestShellDlg :: m_pScreenDib成員是包含圖形並繪製它們的CDIB32位圖類。

我想對當前像素進行採樣,如果它不是黑色(輪廓的顏色),則將其着色爲紅色。這是Dib32.cpp類,吸氣:

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未定義。我不知道爲什麼。任何幫助,非常感激。

回答

0

需要聲明在使用之前(你不能內嵌在參數列表中聲明它們)

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

傳奇先生!非常感謝 –