I have created a closed contour with a list of points which I want to be filled by a color.I have used boundary fill recursion algorithm but no luck the array index goes out of bounds since i cannot develop the if condition since the color inside the closed contour and color outside the contour is same.What method should i use to get the desired contour to be filled up by a specific color.Here is the code that i have tried
public class BoundaryFillAlgorithm {
public static BufferedImage toFill = MemoryPanel.Crect;
static Graphics g1 = toFill.getGraphics();
static int seedx = toFill.getWidth()/2;
static int seedy = toFill.getHeight()/2;
public static void BoundaryFill(int x,int y){
Color old = new Color(toFill.getRGB(x, y));
g1.setColor(Color.BLACK);
if(old!=Color.BLACK){
g1.fillOval(x, y, 1, 1);
BoundaryFill(x+1,y);
BoundaryFill(x,y+1);
BoundaryFill(x-1,y);
BoundaryFill(x,y-1);
}
}
Here's the image
Here's the method call
BoundaryFillAlgorithm.BoundaryFill(BoundaryFillAlgorithm.seedx,BoundaryFillAlgorithm.seedy);