如何在应用程序中创建铲斗填充工具?

时间:2011-03-02 09:06:10

标签: flex actionscript-3 flex4 paint

如何在flex中的paint应用程序中实现一个桶填充工具?

case FILL:
        var b:BitmapData = new BitmapData(width, height);
        b.draw(this);
        b.lock();
        var from:uint = b.getPixel(x,y);

        var q:Array = [];

    var xx:int;
    var yy:int;
            var w:int = b.width;
        var h:int = b.height;
        q.push(y*w + x);
        while (q.length != 0) {
               var xy:int = q.shift();
        xx = xy % w;
            yy = (xy - xx) / w;
            if (b.getPixel(xx,yy) == from) { 
                b.setPixel(xx,yy,SolidColorStroke(stroke).color);
                if (xx != 0) q.push(xy-1);
                    if (xx != w-1) q.push(xy+1);
                if (yy != 0) q.push(xy-w);
                if (yy != h-1) q.push(xy+w);
                }
            }
            b.unlock(null);
            break;

Abdul Khaliq

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用Bitmapdata.floodFill