2

我想使用 bitmapData.floodfill() 方法通过使用“onclick”事件来填充图像(就像油漆桶一样)。但问题是,当我使用透明图像(png,gif)时,这种方法不起作用。当我使用不同的东西(如蓝色、红色等)时,它只会使用白色(或我认为的 alpha=0)填充。这是我用红色 clip2net.com/s/2nW65 填充 Jerry 鼠标时的样子,这是我使用嵌入图像的示例:

    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);
    }

当我将 png 或 gif 更改为 JPEG 时,填充开始工作,但它会充满严重的视觉问题,例如http://clip2net.com/s/2nW4J。这是示例https://dl.dropbox.com/u/78904724/as_host/flood_fill.rar的完整来源 (您可以在 Resource.as 中将 jerry.gif 更改为 jerry.jpg)

另外,对不起,如果这是一个愚蠢的问题和我的英语水平低下。

4

1 回答 1

1

内置的 floodFill 不实现锯齿,它只填充精确的颜色,因此为了能够在没有伪影的情况下填充 png 需要准备(基本上去除锯齿像素)。或者像这里一样找到新的洪水填充算法

此致

于 2012-10-11T10:22:17.837 回答