Floodfill



  • Hi,

    bin auf der Suche nach einen Floodfill Algorithmus wie es ihn in GDI gibt,
    nur aber für GDI+. Kennt jemand ein Tutorial oder Sourcecode dafür ?? Das wäre
    echt spitze.

    Gruß
    paddy



  • Keiner ne Idee 😞 ??

    Ich habe jetzt diese Funktion :

    void CChildView::FloodFill(int x, int y)
    {
    	Color c;
    	pic->GetPixel(x, y, &c); // pic = Bitmap Typ
    
    	if(c.GetRed() == lim.GetRed() && c.GetGreen() == lim.GetGreen() && c.GetBlue() == lim.GetBlue())
    	{
    		pic->SetPixel(x, y, cur_color); 
    		FloodFill(x - 1, y);			
    		FloodFill(x + 1, y);		
    		FloodFill(x, y + 1);		
    		FloodFill(x, y - 1);			
    	}
    }
    

    lim ist die Grenzfarbe und wird gesetzt sobald mit der Maus ins Bild geklickt
    wurde.

    Leider stürzt die Funktion mit einem Stack Overflow in der Funktion GetPixel
    ab 😕

    Das komisch ist das ich kleinere Figuren zb. Rechtecke & Kreise problemlos
    füllen kann. Aber will ich zb. ein komplett weißes Bild (640x480) damit füllen
    stürzt er ab. 😞



  • Warum benutzt du denn nicht die GDI Funktion? Es wird doch sicherlich bei GDI+ die Möglichkeit geben an das Device Context Handle zu kommen.



  • Das habe ich schon versucht.

    CPaintDC dc(this);
    CDC memDC;
    memDC.CreateCompatibleDC(&dc);
    
    HBRUSH hbrush;
    hbrush = CreateSolidBrush(RGB(255, 0, 255)); // Testfüllfarbe
    SelectObject(memDC, hbrush); 
    
    COLORREF t = RGB(255, 255, 255); // Testgrenzfarbe weiß
    bool result = memDC.FloodFill(400, 250, t);
    
    DeleteObject(hbrush);
    
    dc.BitBlt(0, 0, x_size, y_size, &memDC, 0, 0, SRCCOPY);
    

    Der Code wird problemlos ausgeführt, FloodFill gibt auch TRUE zurück,
    was laut MSDN bedeutet das alles geklappt hat. Aber ich sehe nichts auf
    dem Bildschirm 😕

    edit : hab auch mal das FloodFill weggelassen und nur probiert ne
    Linie in den memDC zu zeichnen. Das klappt auch nicht 😕 BitBlt ist doch
    korrekt, woran haperts ???

    Gruß
    paddy



  • Wollte nur sagen das ich das Problem nach zig Stunden endlich gelöst hab.
    Bzw. gelöst bekommen hab 😉 (Vielen Dank hier nochmal an PixelShader!!)

    CDC *pdc = this->GetDC();
    CDC memDC; 
    
    Color co;
    pic->GetPixel(m.x, m.y, &co);
    COLORREF limit = RGB(co.GetR(), co.GetG(), co.GetB());
    
    memDC.CreateCompatibleDC(pdc);
    CBitmap bild;
    bild.CreateCompatibleBitmap(&dc, x_size, y_size);
    
    memDC.SelectObject(&bild); 
    
    CBrush brush;
    brush.CreateSolidBrush(cur_color);
    memDC.SelectObject(brush);
    
    memDC.BitBlt(0, 0, x_size, y_size, pdc, x_off, y_off, SRCCOPY);
    memDC.ExtFloodFill(m.x, m.y, limit, FLOODFILLSURFACE);
    pdc->BitBlt(x_off, y_off, x_size, y_size, &memDC, 0, 0, SRCCOPY);
    
    DeleteObject(brush);
    DeleteObject(bild);
    this->ReleaseDC(pdc);
    
    delete pic;
    pic = Bitmap::FromHBITMAP(bild, NULL);
    

Anmelden zum Antworten