1
votes

I am creating a user interface and actualy drawing bitmap this way:

HDC hdcMem = CreateCompatibleDC(hdc);

HBITMAP oldBmp = (HBITMAP)SelectObject(hdcMem, mouseover? bitmapover:bitmap);    

StretchBlt(hdc, xabs, yabs, width, height, hdcMem, 0, 0, worg, horg, SRCCOPY);

SelectObject(hdcMem, oldBmp);
DeleteDC(hdcMem);

But I can only draw flat images and I need to draw transparent ones (several alpha levels). I tried things with GetDIBits and SetDIBits but I failed drawing anything. I can use png or modify the bitmap pixel by pixel which is simpler, I just want to avoid using libraries with dlls or restrictive licences.

1
Use OpenGL, there are no licenses or real libraries - Mikhail
Use PNG files without background. Create it in Photoshop - sam
@Mikhail: I don't believe you can alpha-blend an OpenGL render context onto a native window. Even if, OpenGL is extremely complex and expensive to use for something as simple as rendering an image with alpha transparency. - IInspectable
This is code that worked 30 years ago. GDI is pretty stuck in the sensibilities of 30 year old hardware, it is restricted to 24bpp pixel formats and that makes transparency effects painful. Things did improve since then, Windows has built-in support for PNG decoding and 32bpp formats with an alpha channel. Start here. - Hans Passant

1 Answers

1
votes

To draw semi-transparent bitmatps you can utilize GdiAlphaBlend function. Note that bitmap with alpha channel that you are going to draw using this API need to have premultiplied alpha.