C++/VB - TextOut to a 32-bit bitmap for AlphaBlend on Vista x64

Asked By akiril
27-May-08 12:04 AM
Hello,

Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
bitmap, created with CreateDIBSection, so that bitmap can later be AlphaBlend
to a paint DC.
In pseudo code:
1. paintDC = BeginPaint()
2. compatibleDC = CreateCompatibleDC (paintDC)
3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
biSizeImage=0)
4. Select bitmap into the compatibleDC
5. fill the bitmap with some ARGB color
6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and any
text color (SetTextColor).
7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA

A string, used on step 6, is not visible when executed on Vista x64 (no
composition).

Note: steps 1-5, 7 are taken from Alpha Blending a Bitmap
(http://msdn.microsoft.com/en-us/library/ms532295(VS.85).aspx)

The real application uses a compatibleDC as an offscreen and drawing
directly to the paintDC is almost not an option.

Test systems: 32-bit XP SP2 and 64-bit Vista Business. Several other 64-bit
systems (some Intel-, some AMD-based) has the same problem, hence video
driver does not seem to contribute to a problem.

So, is it a known "limitation"? Or am I missing something obvious?

Side question: on 32-bit XP SP2, the behaviour of TextOut (step 6) is
different, depending on which brush is used during class registration. For
example, wcex.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); works, but
(HBRUSH)(COLOR_WINDOW+1) causes the string to appear in a wrong color on a
wrong background.

Thank you for your time!

--
Kirill.
Windows XP
(1)
Windows Vista
(1)
Vista
(1)
XP
(1)
CreateCompatibleDC
(1)
GetStockObject
(1)
SetTextColor
(1)
SetBkColor
(1)
  Somebody replied...
27-May-08 02:08 AM
Thats because GDI functions mostly only know about RGB, not ARGB. *MOST* GDI
functions will set the A channel to 0 and thus make your text transparent.
You'll find even basic functions like FillRect() and SetPixel() don't work
correctly when writing to ARGB surfaces.

So the way you need to do it is to build your bitmap on a 24bit RGB surface,
then after you are done, loop through and set the A channel to 0xff and then
AlphaBlend() and WS_EX_LAYERED will work as expected.
  Michael Phillips, Jr. replied...
27-May-08 09:21 AM
Is there any reason why you cannot switch steps 6 and 7?

The AlphaBlend function requires that the pixels in the bitmap be
premultiplied by the alpha channel.

If the alpha channel contains a pixel color greater than zero and not 255,
then the rgb channels will have their color intensity changed.

Your text will have its rgb color intensity altered in those areas of the
bitmap.

If the alpha channel is 0, then those rgb channels in the bitmap will be
completely transparent.  Your text will disappear, if it falls within those
areas.
  Kirill replied...
27-May-08 10:13 AM
Hello,

It's true and I'm aware of that, but unfortunately it does not explain why
the code works correctly under 32-bit Windows XP.

I thought about this as well and it indeed fixes the problem. Unfortunately,
I'm not sure how well it will work with TextOut and ClearType (seemingly,
the latter may use alpha channel).

--
Kirill.
  Kirill replied...
27-May-08 10:21 AM
Michael,

Well... in a sample application it does fix the problem. But in the real
application steps 2 (using window's DC) through 6 are not a part of WM_PAINT
event handler. And it would be difficult to bring step 6 into WM_PAINT.

I've read about that, and even though it does not explain why it works under
32-bit Windows XP, your comment makes me wonder who's responsible for
pre-multiplying? If a bitmap is supposed to be pre-multiplied by the caller,
then 64-bit Windows Vista is very likely to be broken, because I verified
the pixels' values and in a simple test they're all relatively good (e.g.
0x00FFFFFF when drawing with white). If the pre-multiplication is done
inside of AlphaBlend, then looks like TextOut is broken on 64-bit version,
because it seemingly fills alpha with 0.

--
Kirill.
  jeta replied...
27-May-08 10:22 PM
Hi Kirill,

Can you send an email to me at: jetan@online.microsoft.com(remove

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
help
Windows Vista / Windows XP Application Load Failure C++ / VB Hello, I seem to be having an issue with Visual Studio 2005 Professional on Windows Vista Ultimate. It seems to me that whenever I build an MFC application (which contains several DLLs and an exe), the application runs beautifully on Windows Vista (e.g. my development machine). However, when I attempt to run it on Windows XP
DeviceIOControl Windows Vista C++ / VB We made some DLL with Visual C and it was compile with Windows XP. When using those DLL on a PC with Windows Vista, it "freezes" on DeviceIOControl. Any suggestions to fix the problem? Should we compile with Windows Vista? - - Mario VC Language Discussions Windows XP (1) Windows Vista (1) DeviceIOControl (1) Boekelheide (1) Providenza
compatible AEC for both windows Vista and windowsXp C++ / VB Hi, friends I wanted to know that is there any comman method to obtaine AEC(acoustic echo cancellation) on both Windows Vista and Windows Xp. Because, I read that the WASAPI will work only for the Windows Vista.And It will show error's in windows XP. Please any one is having the
Send wake on lan from windows XP / Vista C++ / VB Hi, I'm trying to find a windows API that will allow me to write some code to send wake on lan packets from a C++ windows application (XP and Vista). I've tried searching msdn + google but didn't have much success. I'd appreciate some links and / or the names of the API functions. Thanks. Dave. Win32 Networks Discussions Vista (1) XP (1) WinAPI (1) Windows (1) Packets (1) WOL (1) There isn't an
IbasicAudio implementation not working fine in Windows Vista C++ / VB Hi All, I have implemented IBasicAudio interface in my filter. I want to Audio renderer. The problem i am facing is that this implementation is working fine in Windows XP but somehow it is not working fine in Windows Vista. Windows Media Player doesn't call the IBasicAudio methods properly in case of Windows Vista. In Windows Vista I am receiving only the call for IBasicAudio:: get_Volume() & put_Volume method