ClearType ruins transparency

425 Views Asked by At

I have a bitmap which background needs to be replaced with part of another bitmap. Everything works fine until I enable ClearFont on my WindowsXP.

In order to explain my problem better, let us label first bitmap as bmpDestination and second as bmpSource.

Here is how the bmpSource looks like :

enter image description here

Here is how bmpDestination looks like :

enter image description here

When ClearType is off, here is how the correct result looks like :

enter image description here

And here is the incorrect result of their combining when ClearType is on:

enter image description here

ClearType alters some parts of the text background color, so they aren't white anymore ( RGB( 255, 255, 255 ) ) but a combination of white and text color.

I am using BitBlt() and monochrome bitmap to create a mask, and to simulate transparency. I have tried using TransparentBlt() too, but got the same result.

How can I combine bmpSource and bmpDestination, when ClearType is enabled, so I can create correct result like above ?

Thank you for your help.

Best regards.

1

There are 1 best solutions below

1
arx On

Render the treeview with black text on a white background. Use a font with grey-scale anti-aliasing. Don't use ClearType anti-aliasing. I'm moderately sure you can achieve this with one of the fdwQuality parameters to CreateFont, but I wouldn't swear to it.

Each pixel will have a shade of grey between white and black. You can interpret this as transparency. White is fully transparent; black is fully opaque. Use this information to create a bitmap with transparency. Render this transparent bitmap over your multi-coloured background.