Sver
Full Member
Posts: 145
|
Post by Sver on Jun 27, 2018 6:16:04 GMT -5
Floodfillborder works, but how to use floodfillsurface? I don't know how to def. nomainwin ' fill to the border with one color WindowWidth =500 WindowHeight =500 open "Fill-me" for graphics_nsb as #wg #wg "trapclose [quit]"
hw =hwnd( #wg)
calldll #user32, "GetDC", hw as ulong, hdc as ulong
picture$="500.bmp" loadbmp "scr", picture$ #wg "down" #wg "drawbmp scr 0 0" #wg "flush"
fillCol$ = "255 0 0" 'newcolor/red
#wg "backcolor "; fillCol$
xVar=1:yVar=1 'start position to fill
crColor=0 ' this is the longcolour of the outline to fill out to (this case black)
calldll #gdi32, "ExtFloodFill",_ hdc as ulong,_ xVar as long,_ yVar as long,_ crColor as long,_ FLOODFILLBORDER as long,_ 'fill out 'til this colour is met.. result as long
'calldll #kernel32, "Sleep", 100 as long, ret as void wait
[quit] calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void 'release the DC close #wg
|
|
|
Post by Rod on Jun 27, 2018 10:14:26 GMT -5
I'm not at my own PC but from memory. FloodFillBorder uses the color defined in crcolor as the boundary, so if you place the starting position inside an area that is not that color it will be flood filled with the current brush up to that crcolor border. So several colors can be flood filled. If you use FloodFillSurface it will use crcolor as the bounding area to fill with the current brush. So if you set the current drawing color to red and place the cursor inside a yellow area and set crcolor to yellow that yellow area will be flood filled red. The brush and the crcolor are two different things.
|
|
|
Post by tenochtitlanuk on Jun 27, 2018 15:32:13 GMT -5
Here's a demo of the two- it either fills out to chosen boundary colour, over all other colours OR fills out for as long as it is on the chosen colour.
nomainwin
UpperLeftX = 10 UpperLeftY = 10
WindowWidth =530 WindowHeight =540
prompt "Enter 0 ( surface) or 1 ( border)"; response$ if not ( instr( "10", response$)) then end
type = val( response$) ' 0 for boundary, 1 for surface <<<<<<<<<<<<<<<< Change to try each fill type.. <<<
open "Fill-er-upper" for graphics_nsb as #wg
#wg "trapclose quit"
hw =hwnd( #wg) ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< calldll #user32, "GetDC", hw as ulong, hdc as ulong ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#wg "down"
for i =1 to 50 r =int( 192 +64 *rnd( 1)) g =int( 192 +64 *rnd( 1)) b =int( 192 +64 *rnd( 1)) fillCol$ =str$( r) +" " +str$( g); " " +str$( b)
#wg "up ; goto "; int( 500 *rnd( 1)); " "; int( 500 *rnd( 1)); " "; int( 500 *rnd( 1)) #wg "color "; fillCol$ #wg "backcolor "; fillCol$ #wg "down ; circlefilled "; int( 50 +150 *rnd( 1)) next i
#wg "up ; goto 250 180 ; down ; color 0 0 120 ; circle 120 ; up"
x =250 y =250
calldll #gdi32, "GetPixel", hdc as ulong, x as long, y as long, pixcol as ulong bl = int( pixcol /( 256*256)) gr = int( (pixcol -bl *256*256) / 256) re = int( pixcol -bl *256*256 -gr *256)
c$ =str$( re); " "; str$( gr); " "; str$( bl)
#wg "color red" #wg "backcolor red"
notice "Watch the fill and where it goes out to.. it will fill red out from centre to the original" +_ " colour boundary, or to the circle outline, depending on your choice of 0 or 1. Run several times." +_ " NB this program fills FROM the centre ( 250, 250)"
x =250 y =250
if type =1 then targetcolor =120 *2^16 ' This is 120/256 blue. Colour = blue*2^16 +green *2^8 +red. calldll #gdi32, "ExtFloodFill",_ hdc as ulong,_ x as long,_ y as long,_ targetcolor as long,_ _FLOODFILLBORDER_ as long,_ result as long ' ie floodfill out until this targetcolor is met... <<<<<<<<<<<<<<<<<<<<<<<<<< else targetcolor =pixcol ' this is the border colour to be replaced up-to. Works OK. calldll #gdi32, "ExtFloodFill",_ hdc as ulong,_ x as long,_ y as long,_ targetcolor as long,_ _FLOODFILLSURFACE_ as long,_ result as long 'floodfill out wherever this colour is met... <<<<<<<<<<<<<<<<<<<<<<<<<< end if
'calldll #kernel32, "Sleep", 100 as long, ret as void' delay not needed here
scan
wait
sub quit h$ calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void 'release the DC <<<<<<<<<<<<<<<<<<<<< close #wg end end sub
|
|
|
Post by tsh73 on Jun 27, 2018 16:19:58 GMT -5
Thanks John. Nice thing to know.
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Jun 28, 2018 2:29:20 GMT -5
Thanks everyone ! Tenochtitlanuk, i think you did recognized your code, but the second example is better for me.
I did replace floodfillborder, but then, i have to tell the orig color. In my case : pixcol=16777215 'color to replace (white) I can use it in a spritemaker program.
nomainwin ' fill surface with more bordercolors (replace)
WindowWidth =500
WindowHeight =500
open "Fill-me" for graphics_nsb as #wg
#wg "trapclose [quit]"
hw =hwnd( #wg)
calldll #user32, "GetDC", hw as ulong, hdc as ulong
picture$="500.bmp"
loadbmp "scr", picture$
#wg "down"
#wg "drawbmp scr 0 0"
#wg "flush"
pixcol=16777215 'longcolor to replace (this case white)
fillCol$ = "255 0 0" 'new color (red)
#wg "backcolor "; fillCol$
x=1:y=1 'startposition
'of course you can use mouseposition for it.
'of course you can use pixelcolor for replace/newcolor.
targetcolor = pixcol
calldll #gdi32, "ExtFloodFill",_
hdc as ulong,_
x as long,_
y as long,_
targetcolor as long,_
_FLOODFILLSURFACE as long,_
result as long 'floodfill out wherever this colour is met... <<<<<<<<<<<<<<<<<<<<<<<<<<
'calldll #kernel32, "Sleep", 100 as long, ret as void
wait
[quit]
calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void 'release the DC
close #wg
Simple example
|
|
|
Post by tenochtitlanuk on Jun 28, 2018 6:26:41 GMT -5
I'd encourage anyone to use floodfills if they enjoy colourful graphics. Other examples on my website
|
|
|
Post by tenochtitlanuk on Jun 28, 2018 17:18:13 GMT -5
See the two types in action- colouring out from the centre.
|
|