Jump to content
  • Advertisement
Sign in to follow this  
K4W4H33

Creating a BITMAP from a DC

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about creating a DIB or similiar for a DC? I've just been told by Microsoft that because GDI is so advanced, it ignores the alpha channel on a 32bit colour just for the hell of it, so I've been instructed to draw the text on a grayscale DIB, use that as the alpha then inject it into another ARGB DIB with the text on it. A quick response w/ some sample code would be great, thanks.

Share this post


Link to post
Share on other sites
Advertisement
Dammit, I just had a 7-page reply ready that I've spent the past 2 hours typing up, explaining in great detail all the intricacies of the Win32 GDI, and now I'm not going to post it.

Share this post


Link to post
Share on other sites
This is a specific and somewhat obscure question, which the overwhelming majority of people here will not have an answer to, and the remaining percentage aren't nessicarily on 24/7. Expecting an answer in an hour and 40 minutes is a little optimistic, don't you think?

Share this post


Link to post
Share on other sites
Quote:
Original post by Nemesis2k2
This is a specific and somewhat obscure question, which the overwhelming majority of people here will not have an answer to, and the remaining percentage aren't nessicarily on 24/7. Expecting an answer in an hour and 40 minutes is a little optimistic, don't you think?


There was a response here, but it apparently has been deleted.

Quote:
Post by Tim
Dammit, I just had a 7-page reply ready that I've spent the past 2 hours typing up, explaining in great detail all the intricacies of the Win32 GDI, and now I'm not going to post it


I can't tell whether you're being sarcastic or not, but if you're being afflicted by the same thing that was afflicting Nemesis, could you please post it up? It would be appreciated.

Share this post


Link to post
Share on other sites
If you want a DIB for a bitmap that is currently selected into a DC first select something else into that DC so that the bitmap is no longer in it. Then you can use GetDIBits() and CreateDIBSection().

Share this post


Link to post
Share on other sites
Quote:
Original post by K4W4H33
GDI is so advanced, it ignores the alpha channel on a 32bit colour just for the hell of it

GDI was designed 20 years ago. Commodity hardware barely supported color, let alone alpha. And it hasn't been strategic for MS for some time. If you don't like it other options are available - you can always run DX or OpenGL windowed. You can also look at Avalon. All of these modern graphics systems do support alpha natively.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
GDI was designed 20 years ago. Commodity hardware barely supported color, let alone alpha. And it hasn't been strategic for MS for some time. If you don't like it other options are available - you can always run DX or OpenGL windowed. You can also look at Avalon. All of these modern graphics systems do support alpha natively.


Direct3D nor OpenGL have support for layered windows, although Avalon does. At the moment, I need GDI, so I have to use it.

Share this post


Link to post
Share on other sites
Weeelll...I took a brief glance at the MSDN Library's Bitmap docs to refresh my memory. The problem is going to be complex enough that I can't provide sample code for you, being away from my compiler (and even if I were at it, I wouldn't have any way of testing it), but I can suggest something along the lines of:

1) Create a new monochrome bitmap (or any <32bpp) with CreateBitmap, zero it out, and select it to a new DC
2) Render your text to it with DrawText or TextOut
3) Blit it to the DC containing the alpha-channel stuff using TransparentBlt

As long as the bitmap with the text doesn't have an alpha channel, no alpha values should get copied over. I think. The TransparentBlt doc page mentions a concern when using DCs that refer to different devices, but that's probably not a problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!