通常,需要填写代码递归:
public void flood(int x, int y) {
Color originalColor = new Color(imag.getRGB(x, y), true);
if (x > 0 && y > 0 && x <= imag.getWidth() && y <= imag.getHeight()
&& imag.getRGB(x, y) != newColor && imag.getRGB(x, y) == oldColor && originalColor.equals(c)
&& originalColor.getAlpha() == 255) imag.setRGB(x, y, newColor);
else return;
flood(x + 1, y);
flood(x - 1, y);
flood(x, y + 1);
flood(x, y - 1);
}
像洪水一样,但是这件作品:
错误:
线程中的异常&#34; AWT-EventQueue-0&#34; java.lang.StackOverflowError的 在java.awt.image.BufferedImage.getRGB(BufferedImage.java:917)