Floodfill problem still occurring 
Author Message
 Floodfill problem still occurring

Dear all,

Thanks for all your help so far, I have at least managed to get colour on
the screen with thanks to Mike Williams.  The problem now is that the colour
fills the whole circle, and doesn't stop at the line as I would expect it
to, as the border colour is set to 0 (black).

The code I have at the moment is

Private Sub form_load()
AutoSize = True           ' Scale picture to size of imported picture.
Picture = Picture1       ' This should be in your Windows directory
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
 Picture1.FillStyle = 0
Picture1.FillColor = RGB(0, 255, 255)

Picture1.Circle (348.2, 332.5), 313.3
Picture1.Line (348.2, 19.2)-(348.2, 646.8)
Picture1.Line (34.9, 332.5)-(661.8, 332.5)
Picture1.Line (126.7, 110.96)-(569.7, 554)
Picture1.Line (569.7, 110.96)-(126.7, 554)
ExtFloodFill Picture1.hDC, 300, 30, 0, FLOODFILLBORDER
End Sub

Any ideas anyone?

Iain



Mon, 05 Sep 2005 18:56:23 GMT  
 Floodfill problem still occurring
On Thu, 20 Mar 2003 10:56:23 -0000, "Iain Cowan"

Quote:

>Dear all,

>Thanks for all your help so far, I have at least managed to get colour on
>the screen with thanks to Mike Williams.  The problem now is that the colour
>fills the whole circle, and doesn't stop at the line as I would expect it
>to, as the border colour is set to 0 (black).

Try this :-

Option Explicit

Private Declare Function SelectObject _
        Lib "gdi32" _
        (ByVal hdc As Long, _
         ByVal hObject As Long) As Long
Private Declare Function CreateSolidBrush _
        Lib "gdi32" _
        (ByVal crColor As Long) As Long
Private Declare Function DeleteObject _
        Lib "gdi32" _
        (ByVal hObject As Long) As Long

Private Declare Function ExtFloodFill _
        Lib "gdi32" _
        (ByVal hdc As Long, _
         ByVal x As Long, _
         ByVal y As Long, _
         ByVal crColor As Long, _
         ByVal wFillType As Long) As Long
Const FLOODFILLBORDER = 0 ' Fill until crColor& color encountered.
Const FLOODFILLSURFACE = 1 ' Fill surface until crColor& color not
encountered.

Private Sub Command1_Click()
    Dim mBrush&

    mBrush = CreateSolidBrush(vbRed)
    'Select the brush into the device context
    SelectObject Me.hdc, mBrush

    ExtFloodFill Me.hdc, 300, 30, vbBlack, FLOODFILLBORDER
    PSet (300, 30), vbGreen
    DeleteObject mBrush

End Sub

Private Sub Command2_Click()

AutoRedraw = True
ScaleMode = vbPixels
FillStyle = 0
FillColor = RGB(0, 255, 255)

Circle (348.2, 332.5), 313.3
Line (348.2, 19.2)-(348.2, 646.8)
Line (34.9, 332.5)-(661.8, 332.5)
Line (126.7, 110.96)-(569.7, 554)
Line (569.7, 110.96)-(126.7, 554)

End Sub



Mon, 05 Sep 2005 19:36:20 GMT  
 Floodfill problem still occurring
What is happening is that your code is first of all setting the fill style
to solid (Picture1.FillStyle = 0 in your code) and the fill colour to cyan
(Picture1.FillColor = RGB(0, 255, 255)). Then you are drawing a circle
(Picture1.Circle (348.2, 332.5), 313.3). The result is that you end up with
a solid filled cyan coloured circle. Then on top of that circle you are
drawing some black lines (a circumference and some segments or sectors or
whatever they are called). Then you are using the ExtFloodFill API to
position the cursor within one of the sectors and filling that sector (until
the black border line is encountered). The problem is that you are filling
the sector with the same colour you have initially used for the filled
circle, and so you don't see any difference and you end up with exactly what
you had immediately before the ExtFloodFill statement (a cyan circle with
black sectors on it). You need to understand that the ExtFloodFill API uses
the current FillStyle and FillColor of the Picture Box, and so if you want
the filled sector to be something other than cyan (in your specific case)
you have to set the fill colour accordingly before you use the API. Try
changing:

ExtFloodFill Picture1.hdc, 300, 30, 0, FLOODFILLBORDER

to:

Picture1.FillColor = vbYellow
ExtFloodFill Picture1.hdc, 300, 30, 0, FLOODFILLBORDER

Alternatively, if you want the circle to be outline (rahter than filled) you
must set the fill style to transparent when you draw the circle and then to
solid before you use the extFloodFill API. In general, whenever you use the
ExtFloodFill API you must make sure that the fill style and fill colour are
already set to the values you require. Try the following, which should draw
an outline purple coloured circle and purple coloured sectors with one of
the sectors filled in gold:

Dim linecolour As Long
linecolour = RGB(100, 50, 150)
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
'
Picture1.FillStyle = vbFSTransparent
Picture1.ForeColor = linecolour
Picture1.Circle (348.2, 332.5), 313.3
'
Picture1.Line (348.2, 19.2)-(348.2, 646.8)
Picture1.Line (34.9, 332.5)-(661.8, 332.5)
Picture1.Line (126.7, 110.96)-(569.7, 554)
Picture1.Line (569.7, 110.96)-(126.7, 554)
'
Picture1.FillStyle = vbFSSolid
Picture1.FillColor = RGB(200, 150, 50)
ExtFloodFill Picture1.hdc, 300, 30, linecolour, FLOODFILLBORDER

There are many other ways in which you can improve your code. One way would
be to use the appropriate VB constants in place of "magic numbers", as I
have done above, for example, by using Picture1.FillStyle = vbSolid rather
than your own Picture1.FillStyle = 0. Another way would be to calculate the
length and position of your radial lines in code at run time (using a bit of
math) instead of using "magic number constant values" that you have
obviously worked out on paper or by some other method.

As I've said, there are lots of ways you can have a bit of fun with your
code, but the first thing is to understand exactly what is happening (and
why), and I hope I have given you some help there.

Have fun!

Mike


Quote:
> Dear all,

> Thanks for all your help so far, I have at least managed to get colour on
> the screen with thanks to Mike Williams.  The problem now is that the
colour
> fills the whole circle, and doesn't stop at the line as I would expect it
> to, as the border colour is set to 0 (black).

> The code I have at the moment is

> Private Sub form_load()
> AutoSize = True           ' Scale picture to size of imported picture.
> Picture = Picture1       ' This should be in your Windows directory
> Picture1.AutoRedraw = True
> Picture1.ScaleMode = vbPixels
>  Picture1.FillStyle = 0
> Picture1.FillColor = RGB(0, 255, 255)

> Picture1.Circle (348.2, 332.5), 313.3
> Picture1.Line (348.2, 19.2)-(348.2, 646.8)
> Picture1.Line (34.9, 332.5)-(661.8, 332.5)
> Picture1.Line (126.7, 110.96)-(569.7, 554)
> Picture1.Line (569.7, 110.96)-(126.7, 554)
> ExtFloodFill Picture1.hDC, 300, 30, 0, FLOODFILLBORDER
> End Sub

> Any ideas anyone?

> Iain



Tue, 06 Sep 2005 00:22:37 GMT  
 Floodfill problem still occurring
On Thu, 20 Mar 2003 16:22:37 -0000, "Mike Williams"

Quote:

>What is happening is that your code is first of all setting the fill style
>to solid (Picture1.FillStyle = 0 in your code) and the fill colour to cyan
>(Picture1.FillColor = RGB(0, 255, 255)). Then you are drawing a circle
>(Picture1.Circle (348.2, 332.5), 313.3). The result is that you end up with
>a solid filled cyan coloured circle. Then on top of that circle you are
>drawing some black lines (a circumference and some segments or sectors or
>whatever they are called). Then you are using the ExtFloodFill API to
>position the cursor within one of the sectors and filling that sector (until
>the black border line is encountered).

<snip>

Cripes - I missed just setting the FillColor
- all the API brush stuff was pointless



Tue, 06 Sep 2005 16:23:20 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem with FloodFill

2. problem with floodfill and printer

3. FloodFill problems....

4. FloodFill Problems in VB4.0

5. FloodFill problem

6. problem with floodfill and printer

7. Problem with FloodFill

8. Looking for tool to make AVI files from JPG stills

9. Creating time-lapse AVI movie from SNAPPY stills?

10. create fog on a stills picture

11. Pulling PC Cam stills with an API

12. Active connection occurs problem (asp, vb dll , Oracle) but no error message to be raised

 

 
Powered by phpBB® Forum Software