32-bit Alpha Bitmaps and GDI.... (Fun alert)

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So anyway, here I am working on my layered window demo, creating my 32 bit bitmaps with an alpha channel etc. I select the bitmap into a valid device context, and pass it to UpdateLayeredWindow. It works. So I decide to draw text on my DC that I pass to UpdateLayeredWindow. As simple as calling DrawText or TextOut after I've set the colours and background mode, right? WRONG. What happens is that DrawText and TextOut both ignore my alpha channel, and just dump 0 to it. So I end up with a semitransparent window with "STORM System V.1" cut out. My paint procedure:
		case WM_PAINT:
SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkspace, 0);
pXY.x	=	rWorkspace.right - sBitmapXY.cx;
pXY.y	=	rWorkspace.bottom - sBitmapXY.cy;

hBitmap	=	CreateCompatibleDC(NULL);
hScreen	=	CreateCompatibleDC(NULL);

SelectObject(hBitmap, g_hTabbitBmp);
SelectObject(hBitmap, g_hTabbitFntLg);
SetBkMode(hBitmap, TRANSPARENT);
SetTextColor(hBitmap, RGB(127, 127, 127));

TextOut(hBitmap, 0, 0, SC_STORMSYSTEM, _tcslen(SC_STORMSYSTEM));
UpdateLayeredWindow(g_hTabbitWnd, hScreen, &pXY, &sBitmapXY, hBitmap, &pDeviceContextStart, RGB(07, 12, 89), &fBlend, ULW_ALPHA);

DeleteDC(hScreen);
DeleteDC(hBitmap);
return 0;
and the setup for my blend function...
			fBlend.BlendOp				=	AC_SRC_OVER;
fBlend.BlendFlags			=	0;
fBlend.SourceConstantAlpha	=	255;
fBlend.AlphaFormat			=	AC_SRC_ALPHA;
I've sort of locked on to the fact that SetTextColor(HDC, COLORREF) uses COLORREF, which is a 32 bit value. So I tried setting my alpha channel to 255 with that but no, it didn't work. Setting up an RGBQUAD didn't work either. Any help on how to draw the damn text with 255 alpha and Red: 125, Green: 167, Blue: 216 would be VERY appreciated. And if I'm doing something stupid, kick me.

Share on other sites
Alpha support in GDI is sketch at best...

If all else fails you could render your text to an offscreen dib section, if necessary walk the pixels and fixup the alpha, then call AlphaBlend to blt it to a window.

Share on other sites
I had considered myself fairly familiar with GDI and the Win32 API (as well as with finding things in the MSDN Library, hehe); but I don't know and can't find the solution to this problem after some serious searching. Leaving out alpha channel support from the text-drawing functions seems like a major oversight, so it wouldn't hurt to check things out with as simple of a test-case as you can compile and see if it works then; but if not, then you might need to use some sort of mask or other function that fixes or inverts the alpha in the text. I don't know of any off the top of my head...sorry I couldn't be of more help.

Share on other sites
Looks like I'm going to have to do that. Mike Sutton gave me this useful reply in the M\$ community boards:

Quote:
 Most GDI functions have no idea what alpha is and as such simply use a 24-bit colour, ignoring the high byte. What I do is to render the text as an alpha mask to an 8-bit greyscale buffer then use that as the alpha channel in a 32-bit DIB and inject colour into the RGB channels, then AlphaBlend() that to the window.Hope this helps, Mike

Share on other sites
Awesome...have to remember that one myself.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• Forum Statistics

• Total Topics
633003
• Total Posts
3009849
• Who's Online (See full list)

There are no registered users currently online

×