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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionDouble Click problemmemberMember 815980915-Feb-13 10:52 
QuestionquestionmemberMember 976512017-Jan-13 8:32 
GeneralMy vote of 5membervasanth300820-Nov-12 3:39 
QuestionProjectmemberEGHSanc27-Aug-12 3:48 
QuestionClick eventmembermybigfatcatNL10-Aug-12 7:37 
GeneralMy vote of 4memberYawness13-May-12 20:51 
GeneralMy vote of 5membermanoj kumar choubey18-Feb-12 3:29 
QuestionDrawing other stuff on?memberRohit Dubey from Hyderabad22-Jan-12 20:10 
AnswerRe: Drawing other stuff on?memberRohit Dubey from Hyderabad22-Jan-12 20:14 
QuestionImage Sizememberdownsource6-Jan-12 0:51 
Questionform controls TooltipmemberAntonio Pelleriti14-Dec-11 21:45 
SuggestionCan you give use link of whole projectmemberMember 793369229-Jun-11 6:16 
GeneralMy vote of 2memberjoin sam lee25-Jul-10 22:51 
GeneralMy vote of 5memberKPEBEDKO19-Jul-10 2:53 
GeneralThank you!memberEduard Keilholz2-Jul-10 2:41 
AnswerFinding a working image [SOLVED]memberelmernite17-Dec-09 5:25 
GeneralRe: Finding a working image [SOLVED]memberGee.1-Mar-10 12:13 
GeneralAnchor Controls doesnt work if using Per Pixel Alpha Blendmemberdamon8812-Dec-09 21:03 
Generalsmall questionmembernirishere4-Sep-09 15:46 
GeneralAdd ControlsmemberGottdrak9919-Nov-08 12:23 
GeneralRe: Add Controlsmembercolche25-Feb-09 19:52 
GeneralRe: Add Controlsmemberrbrender9-Mar-09 17:44 
GeneralRe: Add ControlsmemberMarko Padjen31-Mar-09 13:39 
GeneralRe: Add ControlsmemberLatencyXXX24-Mar-12 21:36 
GeneralExactly what I was looking for. Thanks.membermlavenne18-Aug-08 11:36 
QuestionGreat but can I use the function also for a control?memberit-bergmann14-Feb-08 1:24 
AnswerRe: Great but can I use the function also for a control?memberMember 420280019-May-09 4:49 
Generalcoolmemberradioman.lt@gmail.com12-Dec-07 22:20 
Questionwhy doing win32 with c#?memberbkaratte11-Dec-07 20:46 
AnswerRe: why doing win32 with c#?membertic8410-Jun-08 13:12 
GeneralVB.Netmemberdawmail33324-Aug-07 22:47 
GeneralRe: VB.NetmemberDj Den4ik11-Feb-08 23:05 
GeneralRe: VB.NetmemberJason Newland25-Apr-12 19:31 
GeneralRe: VB.NetmemberJason Newland25-Apr-12 19:33 
GeneralGreat!!!!!!!!!!!!!membershp-coding9-Aug-07 7:44 
GeneralWay to add some controlsmemberihess30-Jul-07 4:17 
GeneralRe: Way to add some controls [modified]memberSp3cial24-Aug-08 8:12 
GeneralRe: Way to add some controls [modified]memberLatencyXXX23-Jan-11 23:21 
GeneralHelpmembergsampath28-May-07 20:15 
GeneralImage problemmemberdarb220-Apr-07 12:57 
GeneralRe: Image problemmemberDaryl Fish15-Jan-08 14:58 
GeneralProblem when changing the form parent to desktop with dual-monitoring [modified]memberPim-Pom7-Oct-06 1:59 
GeneralNice example, but...membermoebiusproject12-Sep-06 9:35 
GeneralRe: Nice example, but...memberTung Nguyen15-Apr-07 17:37 
GeneralRe: Nice example, but...membertic8410-Jun-08 13:14 
GeneralProblem in design modememberCapt'N Stabbin'12-Jul-06 19:09 
GeneralRe: Problem in design modememberODaniell3-Aug-06 0:52 
GeneralRe: Problem in design modememberMember 420280019-May-09 4:50 
QuestionHow Can I Add Controls?memberranzige2-Dec-05 16:32 
AnswerRe: How Can I Add Controls?memberwang.songqing20-Jun-06 20:16 

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

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