actionscript 3.0 transparent image floodfill

2019-07-12 13:05发布

问题:

I want to use bitmapData.floodfill() method to fill the image by using "onclick" event (like paint bucket does). But the problem is that this method doesn't work as i excepted when i use transparent images(png, gif). It will only fill using white color(or alpha=0 as i think) when i use something different (like blue, red, etc). This is how it looks when i fill Jerry mouse with red color clip2net.com/s/2nW65 and here is the example i used with Embed image:

    var container:MovieClip = new MovieClip(); //container that would hold the image    
    jerry_img = new Resource.jerry_graph(); //jerry image from assets/jerry.gif         

    addChild(container);
    container.addChild(jerry_img);
    container.addEventListener(MouseEvent.CLICK, fill_function);

    public function fill_function(e:MouseEvent):void {              
        jerry_img.bitmapData.floodFill(e.localX, e.localY, 0x00FFFF);
    }

When i change png or gif to JPEG floodfill is starting to work but it would fill with serious visual problems like this http://clip2net.com/s/2nW4J. Here is the full source of example https://dl.dropbox.com/u/78904724/as_host/flood_fill.rar (you could change jerry.gif to jerry.jpg in Resource.as)

Also, sorry if it is stupid question and for my low english skill.

回答1:

built in floodFill doesn't implement aliasing it only fills exact colour, so to be able to fill without artefacts the png needs to be prepared (basically removing aliased pixels). Or finding new flood fill algorithm like here

best regards