Java에서 BufferedImage 클래스의 페인트 통 도구처럼 작동하는 함수를 작성했습니다. 채우기를 수행하기 위해 재귀를 사용합니다. 안타깝게도, 코드를 실행하면 java.lang.StackOverflowError가 발생합니다. 또한 System.out.println을 사용하여 BaseColor의 "빨간색"색상 채널을 검사했을 때 255가 있어야하는 곳에 제로가 부여 된 것과 같이 BaseColor를 인식하지 못한다는 사실을 발견했습니다. (색상은 . 왜 이런 일StackOverflowError Java "Fill Image"함수에서
이public static void BufferedImageFill(BufferedImage bufferedImage, int FillX, int FillY, int FillRed, int FillGreen, int FillBlue, int FillAlpha, int Tolerance, boolean IsFirstPixel, Color BaseColor) {
if (IsFirstPixel == true) {
BaseColor = new Color(RGBAValuesToInt(BufferedImageGetPixelARGB(bufferedImage, "R", FillX, FillY), BufferedImageGetPixelARGB(bufferedImage, "G", FillX, FillY), BufferedImageGetPixelARGB(bufferedImage, "B", FillX, FillY), BufferedImageGetPixelARGB(bufferedImage, "A", FillX, FillY)));
}
if (FillX >= 0 && FillY >= 0 && FillX < bufferedImage.getWidth() && FillY < bufferedImage.getHeight()) {
int ThisR = BufferedImageGetPixelARGB(bufferedImage, "R", FillX, FillY);
int ThisG = BufferedImageGetPixelARGB(bufferedImage, "G", FillX, FillY);
int ThisB = BufferedImageGetPixelARGB(bufferedImage, "B", FillX, FillY);
if (Math.abs(ThisR - BaseColor.getRed()) <= Tolerance && Math.abs(ThisG - BaseColor.getGreen()) <= Tolerance && Math.abs(ThisB - BaseColor.getBlue()) <= Tolerance) {
bufferedImage.setRGB(FillX, FillY, RGBAValuesToInt(FillRed, FillGreen, FillBlue, FillAlpha));
BufferedImageFill(bufferedImage, FillX - 1, FillY - 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX - 1, FillY, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX - 1, FillY + 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX, FillY + 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX, FillY - 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX + 1, FillY - 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX + 1, FillY, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
BufferedImageFill(bufferedImage, FillX + 1, FillY + 1, FillRed, FillGreen, FillBlue, FillAlpha, Tolerance, false, BaseColor);
}
}
}
아무도 알고 있나요 : 흰색는) 다음 코드인가? 주어진 도움 주셔서 감사!
는
이제 ... 통찰력을 가져 주셔서 감사합니다! – neilf