wkf
wkf

Reputation: 842

How do I create a bitmap with an alpha channel on the fly using GDI?

I am using layered windows and drawing a rounded rectangle on the screen. However, I'd like to smooth out the jagged edges. I think that I'll need alpha blending for this. Is there a way I can do this with GDI?

Upvotes: 3

Views: 3651

Answers (3)

Chris Becke
Chris Becke

Reputation: 36026

CreateDIBSection. Fill in the BITMAPINFOHEADER with 32bpp. Fill in the alpha channel with pre-multiplied alpha and youre good to go.

AlphaBlend is the API to actually blit 32 bpp bitmaps with an aplha channel.

Upvotes: 3

Mark Ransom
Mark Ransom

Reputation: 308158

Any chance of using GDI+ instead of GDI? It supports antialiasing and transparency right out of the box.

Upvotes: 0

MusiGenesis
MusiGenesis

Reputation: 75296

You can do this in C# using the LockBits method of the BitMap class (see this question for an explanation). You definitely don't want to use GetPixel and SetPixel for this, as they are hideously slow (even though you'd just be manipulating the edges and not the entire bitmap).

Upvotes: 0

Related Questions