Click here to Skip to main content
Click here to Skip to main content

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

Comments and Discussions

GeneralMy vote of 5 Pinprofessionaltornadofay5-Feb-15 17:22 
QuestionBackground FORM PinmembercThePush8-Aug-14 5:04 
QuestionDoes this work with an MDI Child form? PinmemberBardMorgan1-Jan-14 8:12 
Questioncooll gratz PinmemberMember 1016021017-Jul-13 6:21 
QuestionDouble Click problem PinmemberMember 815980915-Feb-13 11:52 
Questionquestion PinmemberMember 976512017-Jan-13 9:32 
GeneralMy vote of 5 Pinmembervasanth300820-Nov-12 4:39 
QuestionClick event PinmembermybigfatcatNL10-Aug-12 8:37 
GeneralMy vote of 4 PinmemberYawness13-May-12 21:51 
My vote of 4
GeneralMy vote of 5 Pinmembermanoj kumar choubey18-Feb-12 4:29 
QuestionDrawing other stuff on? PinmemberRohit Dubey from Hyderabad22-Jan-12 21:10 
AnswerRe: Drawing other stuff on? PinmemberRohit Dubey from Hyderabad22-Jan-12 21:14 
QuestionImage Size Pinmemberdownsource6-Jan-12 1:51 
Questionform controls Tooltip PinmemberAntonio Pelleriti14-Dec-11 22:45 
SuggestionCan you give use link of whole project PinmemberMember 793369229-Jun-11 7:16 
GeneralMy vote of 2 Pinmemberjoin sam lee25-Jul-10 23:51 
GeneralMy vote of 5 PinmemberKPEBEDKO19-Jul-10 3:53 
GeneralThank you! PinmemberEduard Keilholz2-Jul-10 3:41 
AnswerFinding a working image [SOLVED] Pinmemberelmernite17-Dec-09 6:25 
GeneralRe: Finding a working image [SOLVED] PinmemberGee.1-Mar-10 13:13 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blend Pinmemberdamon8812-Dec-09 22:03 
Generalsmall question Pinmembernirishere4-Sep-09 16:46 
GeneralAdd Controls PinmemberGottdrak9919-Nov-08 13:23 
GeneralRe: Add Controls Pinmembercolche25-Feb-09 20:52 
GeneralRe: Add Controls Pinmemberrbrender9-Mar-09 18:44 

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
Web02 | 2.8.150414.1 | Last Updated 4 Jun 2004
Article Copyright 2002 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid