I am running into a problem when I do a project in my class. I need to fill a closed region with color ( this is a function of paint in window OS ). Hope anyone can help me.
Printable View
I am running into a problem when I do a project in my class. I need to fill a closed region with color ( this is a function of paint in window OS ). Hope anyone can help me.
Welcome to our forum. If you need help, please give us more information that would allow us to help you. Please show us what you've tried and tell us how it's not working, and ask about any specific concepts that you're unclear on. It would help if you also told us what graphics and GUI library you're using.
Our project is to make an application that looks like the paint in Window. We are looking for a solution to the filling a closed region with a chosen color. The problem is that a closed region doesn't have a definite shape ( such as polygon, Oval, ... ), it has an arbitrary shape. Until now, we haven't had any ideas about solving this problem. I hope someone can help me :(
You still haven't told us anything about what library you're using, is it Swing, AWT, SWT, Android, etc... Come on. If you're going to ask for help, at least make it possible for us to help you.
I use Swing (Java) to implement it and the closed region lies on the Jpanel. the problem is that if the closed region is a definite shape such as a rectangle, we can make use of fillrect() - a method of Graphics. A closed region has any form as long as It is closed.
Would the fillPolygon() method work?
I don't think so, because a circle (forr example) is a closed region but not a poygon
It sounds to me that the problem is as much about defining as filling these arbitrary closed shapes you are talking about.
Java provides the Shape interface which has an associated notion of "insideness". It is quite possible your shapes could be implemented as instances of Shape. In that case Graphics2D provides a method for filling them.
Have a read of 2D Graphics in Oracle's Tutorial. It discusses the Shape interface, the builtin classes that implement it and the associated Area class which allows you to build complex shapes out of simple ones. (by union, insection, difference etc).
And if you can't find a suitable implementation of Shape, check out Flood fill - Wikipedia, the free encyclopedia
db