Click here to Skip to main content
11,789,706 members (55,168 online)
Click here to Skip to main content

Per Pixel Alpha Blend in C#

, 3 Jun 2004 422.1K 14.9K 181
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

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

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

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

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