0

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

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by brianlevine
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.