Click here to Skip to main content
13,287,834 members (36,002 online)
Click here to Skip to main content
Add your own
alternative version


185 bookmarked
Posted 11 Feb 2002

Per Pixel Alpha Blend in C#

, 3 Jun 2004
Rate this:
Please Sign up or sign in to vote.
Demonstrates how to create per pixel alpha blending windows

Preview of the per pixel alpha blend effect

Preview of the per pixel alpha blend effect


This is a port of my other article from C++/MFC to C#/Windows Forms. The concept of creating a per-pixel-alpha blending window remains the same, the GDI function UpdateLayeredWindow.

What changed

  • Image loading is handled by GDI+ classes (System.Drawing namespace).
  • No need to pre-multiply the rgb channels with the alpha channel.
  • No more support for PSP files. PNG file are the best choice.


To use this code you need to include PerPixelAlphaForm.cs file in your project, create a class that inherits from PerPixelAlphaForm, load a bitmap using System.DrawingImage.FromFile static method and then call the PerPixelAlphaForm.SetBitmap method.

The example source code is inside the main.cs file. In the source code you will also find the new ways of doing the old things, like, handling dropped files from windows explorer.

Installing & Building

  1. Download and extract the source code of this article;
  2. To build, run the build.bat file from command prompt;
  3. Now, run the bin\main.exe and enjoy!


31 May 2004

  • Fix clipping problems by creating the form without borders.
  • Move PerPixelAlphaForm class to PerPixelAlphaForm.cs file.

12 Feb 2002

  • Initial version.

Do you have any question or comment? Contact me!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Rui Lopes
Web Developer
Portugal Portugal
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Yawness13-May-12 21:51
memberYawness13-May-12 21:51 
GeneralMy vote of 5 Pin
manoj kumar choubey18-Feb-12 4:29
membermanoj kumar choubey18-Feb-12 4:29 
QuestionDrawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 21:10
memberRohit Dubey from Hyderabad22-Jan-12 21:10 
AnswerRe: Drawing other stuff on? Pin
Rohit Dubey from Hyderabad22-Jan-12 21:14
memberRohit Dubey from Hyderabad22-Jan-12 21:14 
Never mind, I created a new bitmap and just drew onto it using Graphics.FromImage.
QuestionImage Size Pin
downsource6-Jan-12 1:51
memberdownsource6-Jan-12 1:51 
Questionform controls Tooltip Pin
Antonio Pelleriti14-Dec-11 22:45
memberAntonio Pelleriti14-Dec-11 22:45 
SuggestionCan you give use link of whole project Pin
Member 793369229-Jun-11 7:16
memberMember 793369229-Jun-11 7:16 
GeneralMy vote of 2 Pin
join sam lee25-Jul-10 23:51
memberjoin sam lee25-Jul-10 23:51 
GeneralMy vote of 5 Pin
KPEBEDKO19-Jul-10 3:53
memberKPEBEDKO19-Jul-10 3:53 
GeneralThank you! Pin
Eduard Keilholz2-Jul-10 3:41
memberEduard Keilholz2-Jul-10 3:41 
AnswerFinding a working image [SOLVED] Pin
elmernite17-Dec-09 6:25
memberelmernite17-Dec-09 6:25 
GeneralRe: Finding a working image [SOLVED] Pin
Gee.1-Mar-10 13:13
memberGee.1-Mar-10 13:13 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blend Pin
damon8812-Dec-09 22:03
memberdamon8812-Dec-09 22:03 
Generalsmall question Pin
nirishere4-Sep-09 16:46
membernirishere4-Sep-09 16:46 
GeneralAdd Controls Pin
Gottdrak9919-Nov-08 13:23
memberGottdrak9919-Nov-08 13:23 
GeneralRe: Add Controls Pin
colche25-Feb-09 20:52
membercolche25-Feb-09 20:52 
GeneralRe: Add Controls Pin
rbrender9-Mar-09 18:44
memberrbrender9-Mar-09 18:44 
GeneralRe: Add Controls Pin
Marko Padjen31-Mar-09 14:39
memberMarko Padjen31-Mar-09 14:39 
GeneralRe: Add Controls Pin
LatencyXXX24-Mar-12 22:36
memberLatencyXXX24-Mar-12 22:36 
GeneralExactly what I was looking for. Thanks. Pin
mlavenne18-Aug-08 12:36
membermlavenne18-Aug-08 12:36 
QuestionGreat but can I use the function also for a control? Pin
it-bergmann14-Feb-08 2:24
memberit-bergmann14-Feb-08 2:24 
AnswerRe: Great but can I use the function also for a control? Pin
Member 420280019-May-09 5:49
memberMember 420280019-May-09 5:49 
Generalcool Pin 23:20 23:20 
Questionwhy doing win32 with c#? Pin
bkaratte11-Dec-07 21:46
memberbkaratte11-Dec-07 21:46 
AnswerRe: why doing win32 with c#? Pin
tic8410-Jun-08 14:12
membertic8410-Jun-08 14:12 
GeneralVB.Net Pin
dawmail33324-Aug-07 23:47
memberdawmail33324-Aug-07 23:47 
GeneralRe: VB.Net Pin
Dj Den4ik12-Feb-08 0:05
memberDj Den4ik12-Feb-08 0:05 
GeneralRe: VB.Net Pin
Jason Newland25-Apr-12 20:31
memberJason Newland25-Apr-12 20:31 
GeneralRe: VB.Net Pin
Jason Newland25-Apr-12 20:33
memberJason Newland25-Apr-12 20:33 
GeneralGreat!!!!!!!!!!!!! Pin
shp-coding9-Aug-07 8:44
membershp-coding9-Aug-07 8:44 
GeneralWay to add some controls Pin
ihess30-Jul-07 5:17
memberihess30-Jul-07 5:17 
GeneralRe: Way to add some controls [modified] Pin
Sp3cial24-Aug-08 9:12
memberSp3cial24-Aug-08 9:12 
GeneralRe: Way to add some controls [modified] Pin
LatencyXXX24-Jan-11 0:21
memberLatencyXXX24-Jan-11 0:21 
GeneralHelp Pin
gsampath28-May-07 21:15
membergsampath28-May-07 21:15 
GeneralImage problem Pin
darb220-Apr-07 13:57
memberdarb220-Apr-07 13:57 
GeneralRe: Image problem Pin
Daryl Fish15-Jan-08 15:58
memberDaryl Fish15-Jan-08 15:58 
GeneralProblem when changing the form parent to desktop with dual-monitoring [modified] Pin
Pim-Pom7-Oct-06 2:59
memberPim-Pom7-Oct-06 2:59 
GeneralNice example, but... Pin
moebiusproject12-Sep-06 10:35
membermoebiusproject12-Sep-06 10:35 
GeneralRe: Nice example, but... Pin
Tung Nguyen15-Apr-07 18:37
memberTung Nguyen15-Apr-07 18:37 
GeneralRe: Nice example, but... Pin
tic8410-Jun-08 14:14
membertic8410-Jun-08 14:14 
GeneralProblem in design mode Pin
Capt'N Stabbin'12-Jul-06 20:09
memberCapt'N Stabbin'12-Jul-06 20:09 
GeneralRe: Problem in design mode Pin
ODaniell3-Aug-06 1:52
memberODaniell3-Aug-06 1:52 
GeneralRe: Problem in design mode Pin
Member 420280019-May-09 5:50
memberMember 420280019-May-09 5:50 
QuestionHow Can I Add Controls? Pin
ranzige2-Dec-05 17:32
memberranzige2-Dec-05 17:32 
AnswerRe: How Can I Add Controls? Pin
wang.songqing20-Jun-06 21:16
memberwang.songqing20-Jun-06 21:16 
Generalrecognition Pin
amir mortazavi26-Jan-05 19:36
memberamir mortazavi26-Jan-05 19:36 
QuestionCan this be done in DirectX? Pin
#teve27-Dec-04 3:58
member#teve27-Dec-04 3:58 
GeneralNice but... Pin
rioman6-Sep-04 6:05
memberrioman6-Sep-04 6:05 
GeneralRe: Nice but... Pin
Rui Godinho Lopes8-Sep-04 14:31
memberRui Godinho Lopes8-Sep-04 14:31 
GeneralRe: Nice but... Pin
rioman9-Sep-04 4:56
memberrioman9-Sep-04 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 4 Jun 2004
Article Copyright 2002 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid