Click to See Complete Forum and Search --> : Flood-fill an area of an image in an applet


wil_cdr
May 11th, 2000, 01:53 AM
Hi,

I have a problem with this java applet that I am developing. The applet will load up an image (a JPEG file specifically) which is black and white only. I want to be able to flood-fill regions of this image... essentially, a simple colouring book type of thing.

Now, I have tried to use java.awt.image.PixelGrabber to find out what the colour of the pixel, and then I have tried to define a recursive function recursive over the 4 pixels around the current pixel, and it will then use fillRect to fill up a rectangle of size 1 which should be just the point itself (or so I hope).. the problem is that it only draws a vertical line up from the pixel I clicked on until it hits a black line. It doesn't fill any of the other areas!!!

And since some of the regions to fill maybe quite big, the recursive function is quite slow (even when it is only drawing that one vertical line up).

Is there a different way I can do this? I have thought of defining a polygon around the pixel I clicked on first, and then just fill the polygon, but I still have to look at the image pixel by pixel, so it may just be the same as the method I have described above.

Please help!!!

Thanks!

Willy