【发布时间】:2017-03-19 16:52:57
【问题描述】:
我创建了一个包含点列表的闭合轮廓,我想用颜色填充这些点。我使用了边界填充递归算法,但没有运气数组索引超出范围,因为我无法开发 if 条件,因为闭合轮廓内的颜色和轮廓外的颜色相同。我应该使用什么方法来让所需的轮廓被特定颜色填充。这是我尝试过的代码
public class BoundaryFillAlgorithm {
public static BufferedImage toFill = MemoryPanel.Crect;
static Graphics g1 = toFill.getGraphics();
static int seedx = toFill.getWidth()/2;
static int seedy = toFill.getHeight()/2;
public static void BoundaryFill(int x,int y){
Color old = new Color(toFill.getRGB(x, y));
g1.setColor(Color.BLACK);
if(old!=Color.BLACK){
g1.fillOval(x, y, 1, 1);
BoundaryFill(x+1,y);
BoundaryFill(x,y+1);
BoundaryFill(x-1,y);
BoundaryFill(x,y-1);
}
}
这是图片
这是方法调用
BoundaryFillAlgorithm.BoundaryFill(BoundaryFillAlgorithm.seedx,BoundaryFillAlgorithm.seedy);
【问题讨论】:
标签: java arrays swing marvin-framework marvinproject