Results 1 to 9 of 9

Thread: [Resolved] ExtFloodFill

  1. #1

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Unhappy [Resolved] ExtFloodFill

    Hi There!

    Does anyone know how to do a floodfill in VB .NET?

    The app is like this:

    I have a black and white image that I have scanned.
    Then you select a color, click anywhere on the image, and the shape is filled.
    Just like an old-style colouringbook.

    I have found a routine to capture the screen, and I can make a floodfill on that image
    without problems, and have that image displayed in a picturebox.

    Then I figured it would be easy. Just replace the desktop DC with my image DC
    using
    VB Code:
    1. hDc = MyGraphics.GetHdc.ToInt32
    But then I just end up with a black
    rectangle covering my entire image.
    It seems that the GetHdc doesnt return the right DC, for the image/bitmap.

    This is really frustrating, especially since I know that all my API's work, if I just have the right DC's.

    Please help... I'm making this app for my son, and he will be very disapointed if I can't get this to work.

    BTW. I have also tried to make a recursive function, that set's
    a pixel, then checks the surrounding pixels, and set's them if they
    have the right color, then calls it'self for the next pixel and so on.
    That also works, but only with small images.
    If the image is too large then i get a stackoverflow exception.
    Last edited by pax; Aug 4th, 2003 at 03:02 AM.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  2. #2

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Thumbs up Resolved

    Hi There.

    Never mind. The problem is solved. I found that the bitblt function
    didn't work with the HDC from a graphics object.
    So after CreateCompatibleBitmap, I create a new graphics object
    FromHdc, so I get a graphics object refering to my new bitmap.
    Then I can just use my DrawImage function from that graphics
    object to draw the image into my bitmap.
    Then I can use the ExtFloodFill function without problems.

    Seems wierd though, that you have to mix GDI and GDI+ to get
    this result, but who cares? As long as it works....
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    New Member
    Join Date
    Oct 2002
    Location
    craiova
    Posts
    4

    Please,I have same problem

    Please I have same problem with ExtFloodFill function in VB.NET.
    If you can ,please, send me the code at [email protected].
    Please it is very urgent.
    PLEASE!!!!!!!!!!!
    Thanks

  4. #4
    New Member
    Join Date
    Oct 2002
    Location
    craiova
    Posts
    4

    Thumbs up Thanks

    Thanks a lot.You really saved my life.
    THANKS.
    I send you a thanks e-mail , from address [email protected](it is my other address).If you need help with something else,ask me, maybe i can help you
    Thanks
    Avy

  5. #5
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Unhappy Re: [Resolved] ExtFloodFill

    Can you aslo send the sample to me? I'm also in the same problem...

    To : [email protected]

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Resolved

    Quote Originally Posted by pax
    Hi There.

    Never mind. The problem is solved. I found that the bitblt function
    didn't work with the HDC from a graphics object.
    So after CreateCompatibleBitmap, I create a new graphics object
    FromHdc, so I get a graphics object refering to my new bitmap.
    Then I can just use my DrawImage function from that graphics
    object to draw the image into my bitmap.
    Then I can use the ExtFloodFill function without problems.

    Seems wierd though, that you have to mix GDI and GDI+ to get
    this result, but who cares? As long as it works....
    It is possible to use bitblt with HDC's of graphics objects, I do it all the time. What exact problem were you having??
    I don't live here any more.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [Resolved] ExtFloodFill

    You should not post your email addreses into ANY open forum.
    Bots will pick it up and you will be spammed by solicitors.
    You can PM your email address to anyone on the board.

    If you must, you should use the word AT instead of the symbol @
    spamMe AT vbforums.com

  8. #8
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Re: [Resolved] ExtFloodFill

    I don't get it work :S...

    If I use it then it will be only white :S

    See the code :

    Code:
     Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
        Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Integer) As Integer
        Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
        Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Integer) As Integer
        Declare Function FloodFill Lib "gdi32" Alias "FloodFill" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer) As Integer
        Declare Function ExtFloodFill Lib "gdi32" Alias "ExtFloodFill" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer, ByVal wFillType As Integer) As Integer
        Declare Function CreateCompatibleBitmap Lib "gdi32" Alias "CreateCompatibleBitmap" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
        Const SRCCOPY As Integer = &HCC0020
        Const SRCINVERT As Integer = &H660046
    
    
        Sub Main()
    
            Dim bmp1, bmp2 As Bitmap
            Dim g1, g2 As Graphics
            Dim hdc1, hdc2 As IntPtr
            Dim oldBmp As IntPtr
    
            bmp1 = New Bitmap("pic.bmp")
    
            g1 = Graphics.FromImage(bmp1)
    
            hdc1 = g1.GetHdc
    
            hdc2 = CreateCompatibleDC(hdc1)
            oldBmp = SelectObject(hdc2, bmp1.GetHbitmap())
    
            ExtFloodFill(hdc2, 5, 5, &HFF00, 0)
    
            BitBlt(hdc1, 0, 0, 50, 50, hdc2, 0, 0, SRCCOPY)
    
            SelectObject(hdc2, oldBmp)
    
            DeleteDC(hdc2)
    
            g1.ReleaseHdc(hdc1)
            g1.Dispose()
            bmp1.Save("test1.bmp")
    
        End Sub
    test1.bmp is just white

  9. #9
    New Member
    Join Date
    Nov 2011
    Posts
    8

    Re: [Resolved] ExtFloodFill

    hi ,
    i have problem with the floodfill algorithm
    i have a form with 4 text boxes use for entering 4 numbers and a commoand button that draws a pie chart depending on the numbers from the text boxes on picture box(pic1) , the problem is that the code draws the outlines of the chart but i want it to be filled with colors
    does anyone know how to do that
    here is the code:

    Private Sub draw_Click()
    Pic1.Cls
    Pic1.DrawWidth = 7
    Sum = Val(Text1.Text) + (Text2.Text) + (Text3.Text) + (Text4.Text)

    p11 = Val(Text1.Text) / Sum * 6.28
    p12 = Val(Text2.Text) / Sum * 6.28
    p13 = Val(Text3.Text) / Sum * 6.28
    p14 = Val(Text4.Text) / Sum * 6.28

    Pic1.Circle (4000, 4000), 1500, vbRed, 0, -p11

    Pic1.Circle (4000, 4000), 1500, vbGreen, -p11, -(p11 + p12)
    Pic1.Circle (4000, 4000), 1500, vbBlue, -(p11 + p12), -(p11 + p12 + p13)
    Pic1.Circle (4000, 4000), 1500, vbYellow, -(p11 + p12 + p13), -6.28
    end sub

    sorry for my weak english , i really need help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width