홍수 채우기가 끝날 때마다 이미지를 다시 샘플링하고 원래 배경과 일치하는 색상을 찾을 때마다 이미지를 다시 시작할 수 있습니다.
홍수 채우기 알고리즘은 한 지점에서 시작하도록 설계되었으며 거기에서 비슷한 색의 영역 인 구속 영역을 채 웁니다. 원이 배경색과 일치하지 않으므로 채우기 알고리즘이 다른 곳을 찾기 위해 "점프"하지 않습니다.
해결 방법은 다른 영역에 범람시키는 것입니다.
public void floodfill(Image img, int x, int y, Color oldColor, Color newColor) {
// Check boundary
if (img.contains(x, y)) {
// Get current pixel color
Color currentColor = img.getColor(x, y);
// Check color match
if (currentColor.equals(oldColor)) {
// Set to new color
img.setColor(x, y, newColor);
// Start again on each of the neighbors
floodFill(img, x - 1, y, oldColor, newColor);
floodFill(img, x + 1, y, oldColor, newColor);
floodFill(img, x, y - 1, oldColor, newColor);
floodFill(img, x, y + 1, oldColor, newColor);
}
}
}
아래 투표를 이해하지 못합니다. upvoted to compens – ldog