Reputation: 600
I am building a Flash Paint application. The basic structure is this.
I have two layers namely topLayer_mc
and bottomLayer_mc
. The actual vector drawing is drawn on the top layer and onmouseUp
of the tool, a bitmap copy of the vector graphics on the top layer is taken and added as a bitmap to the bottom layer. The top layer is cleared subsequently. It is working for the pencil tool.
Now I need to create an eraser tool. This is where things get tricky. In the application there is an option to save the image as png, so alpha has top be preserved. So the coventional method of draw a brush using the vector and using the draw method of bitmap will not work. Of course, on a visual level it would work if the brush drawn using the vector is to have the same color as that of the background.
What I need is to excatly erase the pixels.
Now I have created a brush tool using the conventional technique and clearing is possible but what I need is to exactly erase the pixels. Is there some technique to draw this ?
This is the code that I am using:
I have also uploaded the swf and source code,
http://bobbythecoder.blogspot.com/2011/04/doubt-bitmap.html
When trying out, please draw all over the stage using the pencil (press Pencil button and start drawing)
The source fla is also provided,
http://www.easy-share.com/1914823453/Paint Brush Expt.fla
I have been trying hard for some time so it would be greatly appreciated if you can assist.
topLayer_mc
and bottomLayer_mc
have alpha set to zero now.
I have also not created a draggable brush, just two hard coded positions are cleared. To draw using pencil, just press the pencil button and draw. To clear, just press the eraser button.
What I need is a technique to erase the pixels in the area marked by a brush not just drawing over it.
Upvotes: 0
Views: 1330
Reputation: 11
You can create a bitmap, fill it with a green rectangle
, and then draw a red fill circle
in it. Now, you can use copyChannel, use the source channel as GREEN
, and the destination channel as Alpha
. So, it will end up creating an erase effect with a circular brush.
Upvotes: 1
Reputation: 1937
If you pick through the AS3 documentation you'll find a few things that are significant. First of all, you're trying to draw with blendmode "erase" (BlendMode.ERASE), which only works if the DisplayObject parent Bitmap has it's blendMode changed from flash.display.BlendMode.NORMAL to flash.display.BlendMode.LAYER. If you do intend to use erase mode, I recommend using the constant flash.display.BlendMode.ERASE rather than hardcoding the literal "erase", for forwards compatibility reasons.
But.. you might not be intending to use BlendMode.ERASE, did you pick that intentionally with full knowledge of how it works? It is not necessary to use this blend mode with BitmapData. It should be sufficient for your erase tool to use BlendMode.NORMAL with your BitmapData.draw() operation, and draw transparent pixels of color 0x00000000, which you will get by specifying beginFill(0x000000, 0);
Upvotes: 2
Reputation: 3731
I think I'd create third transparent clip for erasing. When you click on it while holding erasing tool just put whight circle on it.
Upvotes: 0
Reputation: 6689
Drawing transparent pixels (any colour with 0 alpha) should do the trick!
Upvotes: 1