Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing over background but still being shown?

100 views
Skip to first unread message

Sharon

unread,
Dec 21, 2008, 7:57:21 AM12/21/08
to
Hello Gurus,

I'm using VS2005, .NET Framework 2.0.

I'm drawing lines/rectangles/arrow etc. over a background image.
The background image might change it's colors so the lines/rectangles/arrow
I'm drawing will bled in the background and the user may not see it clear
enough.

I want draw the lines/rectangles/arrow so their color will very according to
the behind background image color.
Any idea how to do that?


--
Thanks
Sharon

Chris Hill

unread,
Dec 21, 2008, 11:55:43 AM12/21/08
to

You haven't given enough information about the problem you are trying
to solve to provide a very useful answer. It's unclear which part of
the described scenario you are asking about.

Can anything be assumed about the background or can it be an arbitrary
image?

Do you want the each of the foreground objects to be drawn with a
single color, or can the color of a single object vary (per pixel, per
segment, etc)?

Are you asking how to determine a complimentary foreground color given
a background color? Or do you already know the colors and you want to
know how to draw using those colors?

Chris

Sharon

unread,
Dec 22, 2008, 4:14:10 AM12/22/08
to
Hi Chris,

I'll try...

According to the background image change of colors I need the
lines/rectangles/arrow that I'm drawing to be clearly visible to the user
eye. So the color of the lines/rectangles/arrow must be change according to
the changes of the background colors.I believe that in order to do that there
is a XOR setting of the native GDI, I just haven't used it.

> Can anything be assumed about the background or can
> it be an arbitrary image?

The background is a 256 colors indexed bitmap. The bitmap palette can vary
according to the user GUI. So nothing can assumed about the background, it's
definitely an arbitrary image.

> Do you want the each of the foreground objects to be drawn
> with a single color, or can the color of a single object vary
> (per pixel, per segment, etc)?

I haven't thought whether each of the foreground objects should be drawn
with a single color, or can the color of a single object vary. I guess it
does not matter as long as all of it is clearly shown to the user eye.

> Are you asking how to determine a complimentary foreground
> color given a background color? Or do you already know the
> colors and you want to know how to draw using those colors?

I'm asking how to set the foreground color so it will have the most
emphasized color depending on the background color (like black foreground to
a white background).

Is there a way to do that using the .NET Framework 2.0 GDI Plus?
Or how can I do that in any other way?


--
Thanks
Sharon

Joseph M. Newcomer

unread,
Dec 22, 2008, 11:02:07 AM12/22/08
to
My first idea would be to use one of the NOT/XOR/XORNOT modes and see if this produces an
acceptable result.
joe

Sharon

unread,
Dec 22, 2008, 2:19:01 PM12/22/08
to
That was my guess, but how do I do that?

Note: I'm using C# with .NET Framework 2.0.

--
Thanks
Sharon

Joseph M. Newcomer

unread,
Dec 26, 2008, 8:03:47 PM12/26/08
to
I have no idea in C#, unless I discovered it in my exploration of C#/MFC . You would have
to look at the graphics parts of C# to see what to do, now that it is established what you
need to do.
joe

Sharon G.

unread,
Dec 27, 2008, 4:33:50 PM12/27/08
to
I don't really need the help in C#, I'll use PInvoke to call the Win32 GDI functions.
But I do need to do the drawing using the GDI and the GDI Plus of the .NET Framework.
 
Using the NOT/XOR/XORNOT can be dome solely by the Win32 GDI, So my question is how do I do that?
 
 
--------
Thanks
Sharon

Joseph M. Newcomer

unread,
Dec 29, 2008, 1:31:49 AM12/29/08
to
This is a bit strange, beause GDI and GDI+ are not part of .NET. GDI is a native library
and GDI+ is a user-level native library.

Lines and the outlines of rectangles are drawn using the currently selected pen, in the
currently-selected pen mode. For example, to draw a line over an image using XOR, you
would do

HDC dc;
... initialize DC to the DC somehow...for example, obtaining it from the C# environment...

HPEN pen = CreatePen(PS_SOLID, 0, RGB(255, 255, 255));
SetROP2(dc, R2_XORPEN);
MoveToEx(dc, x0, y0, NULL);
LineTo(dc, x1, y1);

This XORs the color code 255, 255, 255 with the color currently present. If the
background is white, you get a black line. If the background is RGB(255, 0, 0) [red] you
get RGB(0, 255, 255) [cyan] for the line color. If the background is RGB(128, 128, 128) =
RGB(0x80, 0x80, 0x80) then the line is RGB(0x7F, 0x7F, 0x7F) (RGB(127, 127, 127) and it is
going to be hard to see. You can work it out for NOT and XORNOT, and compute a pen color
appropriate for your app.

Solid rectanges pose a different set of problems, and to get these to work, you would have
to draw them on an offscreen bitmap and use BitBlt with an appropriate code, such as
SRCINVERT or one of the many possible BitBlt codes (the enumeration of the parameter
values in the documentation is a subset of the total possible number of values, which is
much more extensive, but can only be expressed in hex). There are 256 possible codes for
BitBlt. Search for "ternary raster operations" in the MSDN for the complete list of codes
and how they combine the bits.

SetROP2 sets the binary ROP code
BitBlt uses ternary ROP codes
MaskBlt, PlgBlt and a few others use quaternary ROP codes

You can also use alpha-blending for solid figures.
joe

0 new messages