Hey,
I have a program that has to draw a polygon, then apply a recursive function that fill the polygon with a color. Unfortunately, I cannot use the fillpolygon() function, but have to make my own function. I have developed a code for any small polygons. But if I apply my code to large images, I get buffer overflow. This is a recursive function code:

-16776961 = blue
-16711936 = green
-1 = white

  public void fill4(int xpoint, int ypoint )
  {
		int pxl=0;
		pxl = bufImag.getRGB(xpoint,ypoint);
 
		if(pxl != -16776961 && pxl != -16711936 && pxl==-1   )
		{
			bufImag.setRGB(xpoint,ypoint,-16711936);
 
			fill4(xpoint-1,ypoint);
			fill4(xpoint,ypoint-1);
			fill4(xpoint,ypoint+1);
			fill4(xpoint+1,ypoint);
		}
 
  }
Any piece of advise how to fill each point in the diagram, so that the result is the whole polygon is filled