WHY? - Colors of bitmap are shown inverted sometimes.

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

I'm making a custom control. It draws a bitmap in OnPaint, then draws text
over it. This worked fine until I started embellishing the application which
uses the control. At times the image is shown with inverted colors.

Typically it happens when some other form is involved. For example, when I
use the print dialog, after the printing is done, it repaints the area the
print dialogs were shown, and the image is suddenly inverted. Another time
is in implementing a FIND function to search text, which is displayed over
the bitmap. When my FIND dialog closes, the image is shown inverted.
Sometimes I can do something that causes a repaint, and get it returned to
normal, but sometimes the inverted colors stick.

I am disposing every resource created with "New" in my OnPaint prior to exit
of the routine, and doing so in reverse order of creation. All of this is
bracketed within BeginContainer and EndContainer. I am using something I
found for flicker-free display in my NEW() sub for the control:

SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)

What could be causing the inverted colors?
 
Have you looked at any other commercial apps that display images to see if
they exhibit the same behaviour? Could you create a "user initiated twiddle"
in code to clear it up?

To be honest, if one is still using 8-bit displays, it's not likely one is
doing any critical image work, so at worst this problem is an annoyance.

Can you still buy 8-bit video cards?

Colin
 
Hi Lee,
Actually I don't know how it works on GDI+, but in GDI when you use display
mode,which uses palettes (like in your case with 256 colors) you have to
load the system (hardware) palette every time your window becomes active. As
long as all application share the same hardware palette the colors are kind
of insufficient. That's why only the active window uses the colors its
actually needs. And the application's responsibility is to load the hardware
palette with correct values The GDI function for doing this is called
RealizePalette.
So you might check in the .NET and GDI+ documentation if it still works like
this.

HTH
100
 
Back
Top