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

Does it have to be recursive?

Since it works on smaller polygons it sounds like the function is getting called too many times and you're running out of heap space.

Depending on your needs the easiest thing would be to increase the heap. If you're running from the command line you can do this:
java -Xms500m programName

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.