P
pantalaimon
I'm writing a paint program in java and for the moment I am having
trouble with my filling-algorithm. It works fine for smaller areas but
whenever I try to fill my whole screen with it, I get this error. I
can't think of any other way to do this really so please help me!
thanks in advance
public void fillArea(int x,int y)
{
//reveice rgb of wich is to be replaced
int rgb = image.getRGB(x, y);
//fill start pixel
image.setRGB(x, y, currentColor);
//check surroundings
fillSurroundings(x,y,rgb);
}
void fillSurroundings(int x, int y, int replaceColor)
{
try
{
if(image.getRGB(x, y + 1) == replaceColor)
{
image.setRGB(x, y + 1, currentColor);
fillSurroundings(x, y + 1, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x, y - 1) == replaceColor)
{
image.setRGB(x, y - 1, currentColor);
fillSurroundings(x, y - 1, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x + 1, y) == replaceColor)
{
image.setRGB(x + 1, y, currentColor);
fillSurroundings(x + 1, y, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x - 1, y) == replaceColor)
{
image.setRGB(x, y - 1, currentColor);
fillSurroundings(x - 1, y, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
}
trouble with my filling-algorithm. It works fine for smaller areas but
whenever I try to fill my whole screen with it, I get this error. I
can't think of any other way to do this really so please help me!
thanks in advance
public void fillArea(int x,int y)
{
//reveice rgb of wich is to be replaced
int rgb = image.getRGB(x, y);
//fill start pixel
image.setRGB(x, y, currentColor);
//check surroundings
fillSurroundings(x,y,rgb);
}
void fillSurroundings(int x, int y, int replaceColor)
{
try
{
if(image.getRGB(x, y + 1) == replaceColor)
{
image.setRGB(x, y + 1, currentColor);
fillSurroundings(x, y + 1, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x, y - 1) == replaceColor)
{
image.setRGB(x, y - 1, currentColor);
fillSurroundings(x, y - 1, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x + 1, y) == replaceColor)
{
image.setRGB(x + 1, y, currentColor);
fillSurroundings(x + 1, y, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
try
{
if(image.getRGB(x - 1, y) == replaceColor)
{
image.setRGB(x, y - 1, currentColor);
fillSurroundings(x - 1, y, replaceColor);
}
}
catch(ArrayIndexOutOfBoundsException e)
{
//
}
}