Download source code with sample project - 188 Kb
Download ImgDecoder project - 14 Kb
Download some test images - 108 Kb
In this article I will give you some source code to create per pixel alpha blending windows.
First, some images:
For creating a per-pixel window we are going to use:
- One 24bit Bitmap with alpha channel.
- The GDI function,
24bit Bitmap with alpha channel
The most tricky part of creating the bitmap is finding a simple file format that
has an embedded alpha channel.
The selected file format for the first incarnation of this article was PSP (Paint Shop Pro™ from Jasc®), but now the recommended file format has been changed to PNG (Portable Network Graphics).
For loading PNG files I use the paintlib library. This library can also load files from PCX, TGA and TIFF formats.
This demo application does not use paintlib directly; instead it uses a paintlib
wrapper dll, ImgDecoder.Dll.
For loading PSP files I've created a function called
To use this function we must have a top-level window (in this sample this is
implemented by the class
CDummyDialog) with the extended style
Before we can pass the bitmap to the
UpdateLayeredWindow function, we must pre-multiply the rgb channels with the alpha channel. For this you just have to call the
PreMultiplyRGBChannels function (take a look at
From here on read the source code in
Installing & Building
- Make sure you have the SDK for Windows® NT 5.0.
- Download and extract the source code of this article.
- Build and enjoy!
If you want to build the ImgDecoder.Dll you also have to,
- Download paintlib and all the required libraries.
- Download the ImgDecoder project.
- Extract the ImgDecoder project to the paintlib library.
- Build the ImgDecoder project.
- Copy the resulting ImgDecoder.dll and ImgDecoder.lib to the bin directory of this article's demo application.
- You must mention my name in your application documentation/help box,
something like, Portions © 2001 by Rui Godinho Lopes
- I would appreciate it if you send me an email letting me know that you are using this code.
- I cannot be held responsible of any kind of data loss caused directly or
indirectly by the use of this code - use it at your own risk.
- You cannot sell this code - this is free software.
Don't forget if you have any constructive thoughts just email me!