如何在 ActionScript 3 中检测位图中可以填充的区域?
我需要能够检测类似于着色书图片的填充区域。用户将在需要填充的区域内单击。该图像是用户创建的位图内容,因此必须在运行时检测填充区域。
<fx:Script>
<![CDATA[
protected function myImage_clickHandler(event:MouseEvent):void
{
myImage.imageDisplay.bitmapData.floodFill(event.localX,event.localY,0xFFFFFF);
}
]]>
</fx:Script>
<s:Image id="myImage" click="myImage_clickHandler(event)" source="/images/square.gif"/>
I need to be able to detect a fill area for something similar to a coloring book picture. The user will click inside the area that needs to be filled. The image is user created bitmap content and so the fill area must be detected at runtime.
<fx:Script>
<![CDATA[
protected function myImage_clickHandler(event:MouseEvent):void
{
myImage.imageDisplay.bitmapData.floodFill(event.localX,event.localY,0xFFFFFF);
}
]]>
</fx:Script>
<s:Image id="myImage" click="myImage_clickHandler(event)" source="/images/square.gif"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html?filter_coldfusion=9&filter_flex=3&filter_flashplayer=10& ;filter_air=1.5#floodFill%28%29
mouseX 和 mouseY 始终是鼠标位置向任何对象添加点击侦听器并仅使用 mouseX/mouseY 或 MouseEvent 的 event.localX 和 event.localY 对象 如果您使用 Flex 4.5 Hero 框架,则这是
一个解决方案,否则我无法通过 BitmapImage 获取位图数据的句柄,上述解决方案仍然适用于 Flex 3 或 4:
即使它们公开了位图数据在 4.5 框架中,它是只读的,所以我必须复制它并将其重新分配给似乎有效的源
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html?filter_coldfusion=9&filter_flex=3&filter_flashplayer=10&filter_air=1.5#floodFill%28%29
mouseX and mouseY are always the mouse position add a click listener to whatever object and just use the mouseX/mouseY or else the MouseEvent's event.localX and event.localY for the object that the listener is attached to
Here's a solution if you use the Flex 4.5 Hero framework otherwise I was unable to get a handle on the bitmapData through the BitmapImage, the above solution also still works with Flex 3 or 4:
even though they exposed the bitmapData in the 4.5 framework it's read only though so I had to copy it and re-assign it to the source that seemed to work
听起来您正在寻找洪水填充算法。
It sounds like you're looking for a Flood Fill algorithm.