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

Per Pixel Alpha Blend in C#

By , 3 Jun 2004
 

Preview of the per pixel alpha blend effect

Preview of the per pixel alpha blend effect

Introduction

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.

Usage

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!

Changelog

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!

License

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionDouble Click problem PinmemberMember 815980915-Feb-13 10:52 
Questionquestion PinmemberMember 976512017-Jan-13 8:32 
GeneralMy vote of 5 Pinmembervasanth300820-Nov-12 3:39 
QuestionProject PinmemberEGHSanc27-Aug-12 3:48 
QuestionClick event PinmembermybigfatcatNL10-Aug-12 7:37 
GeneralMy vote of 4 PinmemberYawness13-May-12 20:51 
GeneralMy vote of 5 Pinmembermanoj kumar choubey18-Feb-12 3:29 
QuestionDrawing other stuff on? PinmemberRohit Dubey from Hyderabad22-Jan-12 20:10 
QuestionImage Size Pinmemberdownsource6-Jan-12 0:51 
Questionform controls Tooltip PinmemberAntonio Pelleriti14-Dec-11 21:45 
SuggestionCan you give use link of whole project PinmemberMember 793369229-Jun-11 6:16 
GeneralMy vote of 2 Pinmemberjoin sam lee25-Jul-10 22:51 
GeneralMy vote of 5 PinmemberKPEBEDKO19-Jul-10 2:53 
GeneralThank you! PinmemberEduard Keilholz2-Jul-10 2:41 
AnswerFinding a working image [SOLVED] Pinmemberelmernite17-Dec-09 5:25 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blend Pinmemberdamon8812-Dec-09 21:03 
Generalsmall question Pinmembernirishere4-Sep-09 15:46 
GeneralAdd Controls PinmemberGottdrak9919-Nov-08 12:23 
GeneralExactly what I was looking for. Thanks. Pinmembermlavenne18-Aug-08 11:36 
QuestionGreat but can I use the function also for a control? Pinmemberit-bergmann14-Feb-08 1:24 
Generalcool Pinmemberradioman.lt@gmail.com12-Dec-07 22:20 
Questionwhy doing win32 with c#? Pinmemberbkaratte11-Dec-07 20:46 
GeneralVB.Net Pinmemberdawmail33324-Aug-07 22:47 
GeneralGreat!!!!!!!!!!!!! Pinmembershp-coding9-Aug-07 7:44 
GeneralWay to add some controls Pinmemberihess30-Jul-07 4:17 
GeneralHelp Pinmembergsampath28-May-07 20:15 
GeneralImage problem Pinmemberdarb220-Apr-07 12:57 
GeneralProblem when changing the form parent to desktop with dual-monitoring [modified] PinmemberPim-Pom7-Oct-06 1:59 
GeneralNice example, but... Pinmembermoebiusproject12-Sep-06 9:35 
GeneralProblem in design mode PinmemberCapt'N Stabbin'12-Jul-06 19:09 
QuestionHow Can I Add Controls? Pinmemberranzige2-Dec-05 16:32 
Generalrecognition Pinmemberamir mortazavi26-Jan-05 18:36 
QuestionCan this be done in DirectX? Pinmember#teve27-Dec-04 2:58 
GeneralNice but... Pinmemberrioman6-Sep-04 5:05 
GeneralAlpha Blend as a background Pinmembergozza112-Jul-04 2:14 
Generalmulti transparent forms Pinmembermazro328-Jun-04 7:31 
GeneralCreating Slices of an Image PinmemberSameers (theAngrycodeR )9-Jun-04 5:55 
GeneralClipping Problem Pinmembergarythemann5-Apr-04 11:51 
QuestionCan not Hit it at Lasting Windows XP Updata & Windows 2003. Pinmemberwujingping2-Apr-04 5:21 
GeneralUsed your code Pinmemberpardue24-Mar-04 7:40 
QuestionVB.NET Example? PinmemberandrewPP6-Dec-03 11:23 
GeneralNice but superfluous Pinmemberbloodyduke2-Sep-03 7:15 
GeneralWin2K Bug Pinmembernothanks198413-Aug-03 20:39 
QuestionWithout PNG? PinmemberX3m22-Apr-03 2:21 
QuestionControls can be alpha blended? PinsussAnonymous17-Sep-02 14:21 
QuestionCan't add controls? PinsussJason Meistrich22-Aug-02 13:09 14 
GeneralCFileDialog PinmemberAnonymous24-May-02 20:42 
QuestionCan portions of a window be Alpha Blended PinmemberAnonymous19-Feb-02 10:39 
QuestionWin98/ME...? PinmemberMario M.15-Feb-02 6:27 
GeneralNice stuff PinmemberPatrick Hoffmann13-Feb-02 22:42 

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

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