Graphics.FillPath & .DrawPath with AND Logic?

G-Man

Member
Joined
Nov 30, 2006
Messages
6
Programming Experience
10+
When Specifying the brush or pen to be used with Graphics.FillPath or Graphics.DrawPath is there a way to have these operations use AND logic? Failing that, can one specify AND-ing for Graphics.DrawImg?

I'm designing a program to create HeightMaps. The 3d engine I'm using specifies a 24 bit BMP for the height map, but only derives it's height information from the red channel. So I'm using the unused space in the blue and green channels to bit-encode additional information into the hieght map. In the VB6 days, you could use an AND operator when painting an image over top of another. Does .Net maintain this capability? I'm using GraphicPaths to allow the user to specify area type information and it would sure speed things up if I could specify AND-ing behavior for .DrawPath and .FillPath. If that is not possible, then I could draw this information to a scratch image then use .DrawImg with AND-ing. Currently, since I was unable to figure out how to do this (I'm still kind of new to .Net) I've been iterating over the image and manually AND-ing the Blue and Green bits. That's turning out to be painfully slow (go figure).
 
Last edited:
Instance Graphics.CompositingMode can be set to SourceOver. "The blend is determined by the alpha component of the color being rendered." So you have to use a pen/brush where you set the alpha channel of the color used to less than 255. (Color.FromArgb method)
 
Ok, I've tried that and it doesn't seem to work. Keep in mind that I'm attempting to do a bitwise and.

If I have two pixels one colored argb(0,1,0) and the second colored argb(0,128,0), when I combine them using the compositing mode and an alpha value it mixes the two colors based upon a ratio as specified by the alpha value. The approximation of which would be something like (color1 * (255-Alpha))+(Color2 * Alpha)/255... Therefore using an alpha of 128 (@50%) the result of my two mixed colors would be argb(0,64,0) At no point can this return a value greater than either of the two values being composited. The result I'm looking for is argb(0,129,0) ("10000000" AND "00000001" = "10000001"). Keep in mind, each bit bears a significant meaning.
 
Back
Top