Text Transparency using GDI Alpha Blend

  alphablending, c++, gdi

I have a pdf file(Transparent_Text.JPG) with the main context "mark" without any transparency, the watermark text "WA" is made transparent with the opacity of 50% and placed on top of the page.The watermark text "WA" and the main content "mark" is rendered using the GDI StretchDIBits API. Since this API doesn’t have the capability to handle transparency, the text watermark obscures the main content and makes it unreadable(Please check the attachment,Output.PNG).

Hence, I am trying the use the Alpha Blend GDI API to achieve the transparency for the text "WA" so that it won’t obscure any content in the file. All the text characters are stored as bitmaps. I am using the functions in the order described below to achieve this.

  1. CreateCompatibleDC
  2. CreateDIBSection
  3. SelectObject
  4. AlphaBlend

Screenshot of the Input PDF File

Generated Output(using StrectchDIBits)

Output using Alpha Blend

The problem I am facing with the approach is, the watermark text is getting rendered as rectangle boxes(Please check attachment). Although the transparency is getting applied, the text watermark is missing. I have a hard time to figure out how to add the text "WA" to the hdcSrc(handle to Source Device context) in the Alpha Blend. I believe the reason this problem happens is, I am not adding the pre-blended bitmap of the text watermark to the Source context in a proper way.

Any help on this would be greatly appreciated. I am not allowed to use GDI+ to achieve this. I have to manage this using GDI.

Source: Windows Questions C++