封闭区域填充,太慢了...

今天用JAVA写一个封闭图形的填充,
我采用种子填充算法,
/**
*@param x 初始点x坐标
*@param y 初始点y坐标
*@param ccolor 填充颜色
*@param bcolor 初始点颜色
*@param image 图形
*/
public void setColor(int x,int y,Color ccolor,Color bcolor,java.awt.image.BufferedImage image){
ArrayList list=new ArrayList();//边界保存,保存下一次要处理的
//装入原始点
list.add(x);
list.add(y);
while(list.size()!=0){
//填充边界颜色
for(int i=0;i
//if(image.getRGB(list.get(i),list.get(i+1))!=ccolor.getRGB())
image.setRGB(list.get(i),list.get(i+1),ccolor.getRGB());
}
int size=list.size();
int byLength=0;
while(size>0){
int tempx,tempy;
tempx=list.get(0);
tempy=list.get(1);
if(tempx>0){
if(image.getRGB(tempx-1, tempy)==bcolor.getRGB()){//取左边点
list.add(tempx-1);
list.add(tempy);
byLength++;
//System.out.println("("+(tempx-1)+","+tempy+")");
}
}
if(tempy>0){
if(image.getRGB(tempx, tempy-1)==bcolor.getRGB()){//取上边点
list.add(tempx);
list.add(tempy-1);
byLength++;
//System.out.println("("+tempx+","+(tempy-1)+")");
}
}
if(tempx
if(image.getRGB(tempx+1,tempy)==bcolor.getRGB()){//取右边点
list.add(tempx+1);
list.add(tempy);
byLength++;
//System.out.println("("+(tempx+1)+","+tempy+")");
}
}
if(tempy
if(image.getRGB(tempx, tempy+1)==bcolor.getRGB()){//取左边点
list.add(tempx);
list.add(tempy+1);
byLength++;
//System.out.println("("+tempx+","+(tempy+1)+")");
}
}
if(byLength==0)return;
list.remove(0);
list.remove(0);
size-=2;
}
if(byLength==0)break;
}
}
//运算速度太慢了.
//不知道...windows那个画图的填充是怎么实现的,觉得它的速度不错.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值