Groups | Blog | Home
all groups > dotnet drawing api > april 2004 >

dotnet drawing api : How to make an eraser -- need new CompositingMode?



BlueMonkMN NO[at]SPAM email.com
4/26/2004 4:49:40 PM
I am creating a drawing program as part of an application I am making
and have run into something I just can't figure out. How can I make a
nice anti-aliased eraser? My current erase just uses
CompositingMode.SourceCopy with a 0-alpha pen to draw transparency
onto the existing image. This works, but it's rather crude when the
rest of the tools are nicely anti-aliased. What I would like is a
Compositing mode that "subtracts" color from the target image instead
of adding or replacing it. I have looked around and can't find any
BlueMonkMN NO[at]SPAM email.com
4/30/2004 4:10:49 AM
[quoted text, click to view]

Can anyone confirm or deny the existence of a solution for this
problem? Is there a way to simply erase pixels with anti-aliasing in
Frank Hileman
4/30/2004 5:27:28 AM
If you are looking for an operator that modifies the alpha of existing
pixels, in a small area, I don't think you will find one built in. Usually
people create a pen, brush, or image with the same color as the background,
and use that for erasure. If you make the pen, brush, or image partially
transparent, it may achieve the effect you are looking for.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated VS.net graphics editor

[quoted text, click to view]

BlueMonkMN NO[at]SPAM email.com
5/1/2004 7:10:23 AM
Thanks for the reply. Unfortunately the effect I'm looking for is a
true erase that completely erases pixels to alpha = 0, but leaves some
anti-aliased margin of whatever was behind/around the eraser. Using a
transparent pen or brush cannot erase pixels at all when
CompositingMode is overlay and cannot anti-alias the area that it
effects when CompositingMode is Copy (I want to retain some of the
color of whatever was there before around the edges of the eraser).
I'm surprised at how much power GDI+ has and then it leaves out this
simple operation. I suppose the manual method is to Draw whatever
shape I want to erase in a temporary buffer, then take those alpha
values and subtract them from my image pixel by pixel?

[quoted text, click to view]
Frank Hileman
5/1/2004 11:35:52 AM
What about this: Create a small bitmap, clear its pixels to transparent,
create a Graphics from that Bitmap, and draw into it a path gradient fill
the shape of a circle, with the center opaque, the background color, and the
edges transparent. The size of the circle is the size of your eraser. Since
you are using a path gradient it will be opaque at the center and fade to
transparent at the edges. There are many other path gradient parameters you
can use.

Now when you draw this bitmap onto another bitmap, or the screen, it will
"erase" strongest in the center, and less around the edge. It does not erase
by changing alpha, but by covering with the background color.

I think this is as close as you can get -- I don't think there is a way to
modify only the alpha component, short of writing your own pixel
manipulation routines, but it would be nice if someone could prove me wrong!

Regards,
Frank Hileman

[quoted text, click to view]

BlueMonkMN NO[at]SPAM email.com
5/3/2004 5:36:20 AM
Why would I go to all that trouble when I could just create a solid
brush of the background color, set the SmoothingMode to AntiAlias and
get the desired effect? The problem is I don't have a solid
background color. My background is alpha 0 (transparent). In design
mode (when the user is drawing the graphics) I draw whatever the user
wants to put in the background as a backdrop to see the transparency
in action (a diamond or diagonal crosshatch pattern of gray shades).
But I clearly don't want to be putting this in the image being edited
itself. The graphics they are creating need to be able to blend with
any background. Since my primary goal is to erase to alpha 0, I think
SrcCopy is as close as I can get (although I should be able to do
getpixel and setpixel to set the alpha components manually and get
exactly what I need). Anti-aliasing is a secondary goal, and I
definitely wouldn't want to give up being able to truly erase (to
alpha = 0) in order to get it.

[quoted text, click to view]
AddThis Social Bookmark Button