有没有办法找到位图中已使用 bitmapdata.floodfill 方法填充的区域的大小?
基本上,我使用洪水填充方法对位图图像的部分进行着色。这部分很简单,但问题在于我向颜色填充例程添加效果的方式。
为了添加效果,首先创建位图数据的副本,并在其上使用洪水填充而不是原始位图。然后使用bitmapdata.compare方法将除了填充部分之外的所有内容的alpha值设置为0,并将结果保存在另一个bitmapdata中。之后,一个 1 px 半径的圆形精灵被添加到舞台上,并被补间到图像尺寸,并且其遮罩被设置为包含比较操作结果的精灵。
除了填充精灵必须补间到完整的图像尺寸之外,无论着色区域有多大,这都可以完美地工作,因为我无法找到一种方法来获取填充区域的尺寸。我正在补间结束时进行位图图像更新,并且必须禁用用户交互,直到补间完成,以避免在更新基本图像之前启动另一个填充操作时出现的错误。如果我能以某种方式获得填充区域的尺寸,那么我必须禁用用户交互的时间将大大减少。
有什么想法吗?
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 compare 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
getColorBoundsRect?我不知道你的填充颜色是否会出现在位图的其他部分,但它可能会起作用。
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.
我认为 getColorBoundsRect 正是您所需要的。您选择一种颜色并在位图中获取该颜色的边界框。
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.