DrawLine with And or Or Pattern

B

bern11

Is there a way to draw a Line in GDI that will bit-wise AND or bit-wise
OR the target pixel with a desired color? Same question with
fill-patterns. I want to draw in Reb, Blue, & Green, and have the
triple-overlapping region appear as white. I can write my own
algorithm, but if GDI already has the feature, I'd rather use what is
already there. Thankyou.
 
P

Peter Duniho

Is there a way to draw a Line in GDI that will bit-wise AND or bit-wise
OR the target pixel with a desired color? Same question with
fill-patterns. I want to draw in Reb, Blue, & Green, and have the
triple-overlapping region appear as white. I can write my own
algorithm, but if GDI already has the feature, I'd rather use what is
already there. Thankyou.

Well, yes...GDI does support that. See SetROP2() in the Windows API.

However, you're posting in a C# newsgroup, so presumably you want to do
this using .NET Framework rather than using GDI directly. I've never done
this in .NET before, so I went browsing through the docs. I didn't find
much.

Unfortunately, I don't see anything in the Graphics class that
corresponds. There's a CompositingMode that allows you to choose between
overwriting and blending the alpha channel, but it doesn't offer the
variety that SetROP2() does. There's also a CopyPixelOperation
enumeration that has similar pixel-combining operations to those you can
specify in SetROP2(), but as near as I can tell it's only used with the
CopyFromScreen() method. If you know your graphics will always be visible
on the screen when you perform the operation I suppose that would be okay,
but I don't see any more general-purpose use that would allow you to draw
*to* the screen or to an off-screen bitmap.

You can get a DC from a Graphics object, and of course you can use
p/invoke to set the drawing mode for that DC. However, I don't know if
the DC you get from the Graphics.GetDC() method actually affects drawing
done through the Graphics object. Since you have to release it after
you're done, I suspect it's a new DC and that setting the drawing mode for
that DC will only affect operations done through that DC.

Basically, after all that...I don't see any obvious, simple way to do in
..NET what you have always been able to do in GDI. There are some things
that are sort of like it, but short of going unmanaged for the drawing
operations you want to use the different drawing modes, I don't see a
solution that will work exactly right.

I hope I'm wrong and someone jumps in with a correction. :) Seems like a
silly oversight.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top