Basically, I am using the floodfill method to colour-in sections of a bitmap image. That part is easy enough but the issue comes in with the way I am adding an effect to the colour fill routine.
To add the effect, first a copy of the bitmap data is created and floodfill is used on that instead of the original bitmap. Then the bitmapdata.compare method is used to set the alpha value of everything apart from the filled-in section to 0 and the result is saved in another bitmapdata. After that, a 1 px radius circle sprite is added to the stage and is being tweened to the image dimensions and its mask is set to the sprite which contains the result of the compa开发者_JS百科re operation.
This works perfectly except for the fact that the fill sprite has to be tweened to the complete image dimensions irrespective of how small the area is being coloured-in since I am not able to find a way to get the dimensions of the fill area. I am doing an bitmap image update at the end of the tween and I have to disable user interaction till the tween is complete to avoid the errors which come in if another fill-in operation is started before the base image has been updated. If I could somehow get the dimensions of the fill area then the time during which I have to disable the user interaction will go down considerably.
Any ideas?
What about getColorBoundsRect? I don't know if your fill color will be present in other parts of your bitmap, but it might do the trick.
I think getColorBoundsRect is exactly what you need. You choose a colour and get the bounding box of that colour in the bitmap.
Write your own fill routine. As you fill in the pixels, store the dimension info you need. Simplest would be to just store the bounding box. You fill by finding neighboring pixels of the appropriate color, and any time such a move takes you out of working bounding box, adjust.
More complex could store a bitmap. Any way you choose, the point is that you will get what you need more readily by not working around what wasn't designed for.
精彩评论