Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent PNG file in a Pure C++/Win32 Application

Tags:

winapi

I have a pure C++/Win32 VS2005 desktop application. During my WM_PAINT response, when I paint my window, I'd like to be able to Project a transparent PNG image onto my Window.

any pointer will be appreciated.

like image 654
JasonGenX Avatar asked Nov 15 '10 17:11

JasonGenX


2 Answers

The Windows Imaging Component (WIC) is the primary API for native code that provides the ability to encode and decode various image formats. You can use it to load a PNG image into your application.

http://msdn.microsoft.com/library/ee719902

Alternatively you can use GDI+ but that’s pretty old technology and doesn’t work nearly as well. You can also use GDI+ to render the image but I suggest Direct2D.

Direct2D is capable of rendering a WIC bitmap directly on the GPU or in software via a window or bitmap device context.

Here’s an introductory article on Direct2D:

http://msdn.microsoft.com/en-ca/magazine/dd861344.aspx

And this one describes how to use Direct2D with WIC:

http://msdn.microsoft.com/en-us/magazine/ee819134.aspx

like image 23
Kenny Kerr Avatar answered Sep 24 '22 13:09

Kenny Kerr


GdiPlus has been part of Windows since Windows XP at least, and can decode JPEG, PNG and GIF files with ease.

A newer API for dealing with image files is the Windows Image Component. One of the samples covers using WIC to decode an image and GdiPlus to perform the alpha aware painting.

like image 80
Chris Becke Avatar answered Sep 22 '22 13:09

Chris Becke