Selectively erase bitmapdata on a non-solid background
I needed to make the drawing app for a client that allowed users to draw on top of an image and erase what they’ve drawn. Most drawing apps built in Flash allow users to erase, but they cheat by using a solid background and drawing the background color over the user’s drawing when the app is in “eraser” mode. That doesn’t work with a bitmap background.
Dead set on having the erase functionality, I set out to do what seemed to be impossible. After some research and quite a bit of trial and error, I found a solution. Using the BitmapData class’ threshold method, I could isolate drawn pixels in the eraser’s radius and set their alpha to transparent. It’s a little processor intensive but it fit the requirements of the project…almost. As it turns out, the client changed their mind about giving users the ability to erase. So this bit of code didn’t make the cut.
Brian Hadaway is a Senior Interactive Developer at Roundarch in Chicago where he specializes in front-end technologies including HTML/CSS/JS, Flash and Flex. Find him on LinkedIn, Twitter, Facebook and Foursquare.
This entry was posted in Labs. Bookmark the permalink. Both comments and trackbacks are currently closed.
I needed to make the drawing app for a client that allowed users to draw on top of an image and erase what they’ve drawn. Most drawing apps built in Flash allow users to erase, but they cheat by using a solid background and drawing the background color over the user’s drawing when the app is in “eraser” mode. That doesn’t work with a bitmap background.
Dead set on having the erase functionality, I set out to do what seemed to be impossible. After some research and quite a bit of trial and error, I found a solution. Using the BitmapData class’ threshold method, I could isolate drawn pixels in the eraser’s radius and set their alpha to transparent. It’s a little processor intensive but it fit the requirements of the project…almost. As it turns out, the client changed their mind about giving users the ability to erase. So this bit of code didn’t make the cut.
Click here to view Real Erasing in Flash »
About Brian
Brian Hadaway is a Senior Interactive Developer at Roundarch in Chicago where he specializes in front-end technologies including HTML/CSS/JS, Flash and Flex. Find him on LinkedIn, Twitter, Facebook and Foursquare.