我正试着给洪水填水程序,但递归有任何问题。错误信息:“java.lang.StackOverflowError线程中的异常”AWT 0“
这是我的代码:
public class FillerSeedFill<PixelType> {
public RasterImage<PixelType> filler (RasterImage<PixelType> img,
int x, int y,
PixelType newPixel,
PixelType borderPixel,
PixelType currentPixel
){
RasterImage<PixelType> result = img;
if ( borderPixel != currentPixel){
if(currentPixel!=newPixel) {
result = result.withPixel(x, y, newPixel);
filler(img,x+1,y,newPixel,borderPixel,currentPixel);
filler(img,x-1,y,newPixel,borderPixel,currentPixel);
filler(img,x,y+1,newPixel,borderPixel,currentPixel);
filler(img,x,y-1,newPixel,borderPixel,currentPixel);
return result;
}
}
return result;
}
}在画布上:
if(jComboBoxSelectColoring.getSelectedIndex()==0){
System.out.println("Seed fill");
int currentPixel = 0x2f2f2f;
System.out.println(currentPixel);
fillerSeedFill.filler(rasterImage,
previousX,previousY,
0xC4D4AF,
0x8AC249,
currentPixel);
System.out.println(previousX+" "+previousY);
panel.repaint();
}有什么可能改变XSS的想法吗?我记得在Eclipse是这样的。(-XSS100M)
currentPixel是canva的背景(0x2f2f2f)。
编辑: In previousX和Y是来自侦听器的光标的int位置。
编辑解决了:的问题是当前像素没有取颜色的实际值。它有康斯特。0x2f2f2f这样的比较是没有意义的。*)。谢谢大家
发布于 2017-11-09 00:14:24
要在intelliJ中设置arg,可以这样做:定义运行/调试配置的配置选项
资料来源:https://www.jetbrains.com/help/idea/setting-configuration-options.html
发布于 2017-11-09 16:59:31
增加堆栈大小可能是不够的,除了非常小的图像,所以您可能想要改为迭代算法。一个简单的选项是有一个Deque,您可以将坐标填入其中,然后取出它们,类似于下面的伪代码:
Deque<Point> queue = new ArrayDeque<>();
queue.add(new Point(x, y));
while (!queue.isEmpty()) {
Point pt = queue.poll();
// then do the same thing you were already doing, except use pt.x and pt.y,
// and add new points to the queue instead of recursive calling
}https://stackoverflow.com/questions/47191804
复制相似问题