如何在 ActionScript 3 中检测位图中可以填充的区域?

发布于 2024-10-10 18:22:05 字数 440 浏览 7 评论 0原文

我需要能够检测类似于着色书图片的填充区域。用户将在需要填充的区域内单击。该图像是用户创建的位图内容,因此必须在运行时检测填充区域。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉风有信 2024-10-17 18:22:05

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 框架,则这是

<mx:Image id="myImage" click="(myImage.content as Bitmap).bitmapData.floodFill(event.localX,event.localY,0xFFFFFF)" source="http://www.carolynsbloomingcreations.com/images/square.gif"/>

一个解决方案,否则我无法通过 BitmapImage 获取位图数据的句柄,上述解决方案仍然适用于 Flex 3 或 4:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <!--
    <mx:Image
        id="myImage"
        click="(myImage.content as Bitmap).bitmapData.floodFill(event.localX,event.localY,0xFFFFFF)"
        source="http://www.carolynsbloomingcreations.com/images/square.gif"/>
    -->
    <fx:Script>
        <![CDATA[
            private function handleClick(event:MouseEvent):void
            {
                trace('test');
                var tempData:BitmapData = new BitmapData(myBitmapImage.width,myBitmapImage.height);
                tempData = myBitmapImage.bitmapData;

                var localPoint:Point = container.globalToLocal(new Point(mouseX,mouseY));
                tempData.floodFill(localPoint.x,localPoint.y,0xFFFFFFFF);
                myBitmapImage.source = tempData;
                trace(localPoint.x + ":" + localPoint.y);
            }
        ]]>
    </fx:Script>
    <s:Group
        id="container"
        click="handleClick(event)">
        <s:BitmapImage
            id="myBitmapImage"
            source="@Embed('square.gif')" />
    </s:Group>


</s:Application>

即使它们公开了位图数据在 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

<mx:Image id="myImage" click="(myImage.content as Bitmap).bitmapData.floodFill(event.localX,event.localY,0xFFFFFF)" source="http://www.carolynsbloomingcreations.com/images/square.gif"/>

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:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <!--
    <mx:Image
        id="myImage"
        click="(myImage.content as Bitmap).bitmapData.floodFill(event.localX,event.localY,0xFFFFFF)"
        source="http://www.carolynsbloomingcreations.com/images/square.gif"/>
    -->
    <fx:Script>
        <![CDATA[
            private function handleClick(event:MouseEvent):void
            {
                trace('test');
                var tempData:BitmapData = new BitmapData(myBitmapImage.width,myBitmapImage.height);
                tempData = myBitmapImage.bitmapData;

                var localPoint:Point = container.globalToLocal(new Point(mouseX,mouseY));
                tempData.floodFill(localPoint.x,localPoint.y,0xFFFFFFFF);
                myBitmapImage.source = tempData;
                trace(localPoint.x + ":" + localPoint.y);
            }
        ]]>
    </fx:Script>
    <s:Group
        id="container"
        click="handleClick(event)">
        <s:BitmapImage
            id="myBitmapImage"
            source="@Embed('square.gif')" />
    </s:Group>


</s:Application>

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

故人如初 2024-10-17 18:22:05

听起来您正在寻找洪水填充算法。

It sounds like you're looking for a Flood Fill algorithm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文