Click here to Skip to main content
15,126,209 members
Articles / Programming Languages / C#
Posted 11 Feb 2002


190 bookmarked

Per Pixel Alpha Blend in C#

Rate me:
Please Sign up or sign in to vote.
4.72/5 (72 votes)
3 Jun 20041 min read
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 new ways of doing 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!


31st May, 2004

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

12th February, 2002

  • Initial version

Do you have any question or comment? Please leave a note below.


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

Comments and Discussions

GeneralMy vote of 5 Pin
EAHMK28-Jun-20 6:07
professionalEAHMK28-Jun-20 6:07 
QuestionHow I can just place a transparent image to a certain position? Pin
NotNiceCream20-Dec-16 13:41
MemberNotNiceCream20-Dec-16 13:41 
AnswerRe: How I can just place a transparent image to a certain position? Pin
NotNiceCream20-Dec-16 17:15
MemberNotNiceCream20-Dec-16 17:15 
GeneralMy vote of 5 Pin
tornadofay5-Feb-15 17:22
professionaltornadofay5-Feb-15 17:22 
QuestionBackground FORM Pin
cThePush8-Aug-14 5:04
MembercThePush8-Aug-14 5:04 
QuestionDoes this work with an MDI Child form? Pin
BardMorgan1-Jan-14 8:12
MemberBardMorgan1-Jan-14 8:12 
Questioncooll gratz Pin
Member 1016021017-Jul-13 6:21
MemberMember 1016021017-Jul-13 6:21 
QuestionDouble Click problem Pin
Member 815980915-Feb-13 11:52
MemberMember 815980915-Feb-13 11:52 
Questionquestion Pin
wootowl17-Jan-13 9:32
Memberwootowl17-Jan-13 9:32 
GeneralMy vote of 5 Pin
vasanth300820-Nov-12 4:39
Membervasanth300820-Nov-12 4:39 
QuestionClick event Pin
mybigfatcatNL10-Aug-12 8:37
MembermybigfatcatNL10-Aug-12 8:37 
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
professionalManoj 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 
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
Dima Popov19-Jul-10 3:53
MemberDima Popov19-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 

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.