开发者

How can I implement a transparent eraser tool in Flex?

开发者 https://www.devze.com 2023-02-01 20:54 出处:网络
How can I implement an eraser in Flex so that when i开发者_Go百科t erases on an mx:Image, it makes the area transparent?protected function myImage_completeHandler(event:Event):void

How can I implement an eraser in Flex so that when i开发者_Go百科t erases on an mx:Image, it makes the area transparent?


        protected function myImage_completeHandler(event:Event):void
        {
            // TODO Auto-generated method stub
            trace("file loaded");
            var tempBdData:BitmapData = new BitmapData(myImage.contentWidth,myImage.contentHeight,true);
            tempBdData.draw(myImage);
            (myImage.content as Bitmap).bitmapData = tempBdData;
        }

    ]]>
</mx:Script>
<mx:Image
    id="myImage"
    source="http://www.google.com/images/logos/ps_logo2.png"
    complete="myImage_completeHandler(event)"
    mouseDown="(myImage.content as Bitmap).bitmapData.setPixel32(event.localX,event.localY,0x00000000)"/>


Maybe you can try to draw your image in a BitmapData object then use the function setPixel32 :

Example :

setPixel32 (coordX, coordY, 0x60FF0000);

where 0x60FF0000 is :

  • 60 (alpha)
  • FF (red)
  • 00 (green)
  • 00 (blue)


From most erase functions I've seen, not that many I'll admit, it doesn't turn something transparent, ( changing alpha ) , instead it paints with the background color.

YMMV


My approach would be to add a black mask image to your Image component (via the "mask" property), which will have no effect on the image initially, and then paint white into the mask image wherever the user clicks/drags within the image. Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号