Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Mon, 26 May 2008 21:04:00 -0700,    group: microsoft.public.win32.programmer.gdi        back       


TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
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.
date: Mon, 26 May 2008 21:04:00 -0700   author:   Kirill am

Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
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.



"Kirill" <akirill@newsgroup.nospam> wrote in message 
news:96FF6DED-044B-4ED6-9452-F8B6F4558F83@microsoft.com...
>
> 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.
date: Mon, 26 May 2008 23:08:44 -0700   author:   Somebody

Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
> A string, used on step 6, is not visible when executed on Vista x64 (no
> composition).

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" <akirill@newsgroup.nospam> wrote in message 
news:96FF6DED-044B-4ED6-9452-F8B6F4558F83@microsoft.com...
> 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.
date: Tue, 27 May 2008 09:21:01 -0400   author:   Michael Phillips, Jr. 0.c0m

Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
Hello,

"Somebody" wrote...
> 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.
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.

> 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.
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" wrote ...
>> 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).
date: Tue, 27 May 2008 10:13:48 -0400   author:   Kirill am

Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
Michael,

"Michael Phillips, Jr." wrote in message...
> Is there any reason why you cannot switch steps 6 and 7?
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.

> 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.
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.

> "Kirill" wrote ...
>> 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).
date: Tue, 27 May 2008 10:21:32 -0400   author:   Kirill am

Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64   
Hi Kirill,

Can you send an email to me at: jetan@online.microsoft.com(remove 
"online.")? So that we can discuss this issue more efficiently. Thanks.

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.
date: Wed, 28 May 2008 02:22:51 GMT   author:   (Jeffrey Tan[MSFT])

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us