1

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.

7
  • 6
    ClearType blends the foreground and background pixels. In your case, the backgrounds is white. You then try to transfer those pixels to a colored background, so the blending is now all wrong. You need to draw the text directly on the final background. Commented May 11, 2014 at 0:52
  • @RaymondChen: You need to draw the text directly on the final background-unfortunately that is not possible in my case, hence the reason for posting this question. Commented May 11, 2014 at 0:55
  • 1
    (Damn, that tree view custom draw problem again!) Well I'm afraid you can never make a ClearType rendering usable for this kind of composition again -- it just adds so much more than just shades between text color and background color, you can't filter that out automatically even in a full-fledged image manipulation program. Commented May 11, 2014 at 1:12
  • It just isn't going to work. You have to either turn off ClearType or draw the text directly onto the background. I don't know why you say that isn't possible, but if it's not possible, then it's not possible. Commented May 11, 2014 at 1:14
  • 1
    Instead of doing your masked BitBlt, use a memory DC and render the same gradient background into it as you use in your treeview. Then draw the text transparently over the top of the memory DC, and finally do a normal (not masked) blit from the memory DC to the tree. Commented May 11, 2014 at 7:49

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have checked documentation for CreateFont and found nothing for grayscale font. However, I did find a flag ANTIALIASED_QUALITY and tried to create font with it. After setting it as a treeview font everything rendered fine. Still, these are all workarounds for the problem with ClearType... I guess there is no solution for this, only a workaround... Upvoted. Thank you. Best regards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.