Click here to Skip to main content
6,630,586 members and growing! (16,842 online)
Email Password   helpLost your password?
Multimedia » GDI » General     Intermediate

Per Pixel Alpha Blend

By Rui Lopes

Demonstrates how to create per pixel alpha blending windows
VC6Win2K, MFC, GDI, Dev
Posted:30 Mar 2001
Updated:20 Apr 2001
Views:206,451
Bookmarked:79 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
34 votes for this article.
Popularity: 6.45 Rating: 4.21 out of 5
2 votes, 10.0%
1
1 vote, 5.0%
2
1 vote, 5.0%
3

4
16 votes, 80.0%
5
  • Download source code with sample project - 188 Kb
  • Download ImgDecoder project - 14 Kb
  • Download some test images - 108 Kb
  • Introduction

    In this article I will give you some source code to create per pixel alpha blending windows.

    First, some images:

    Nice, heim?

    For creating a per-pixel window we are going to use:

    • One 24bit Bitmap with alpha channel.
    • The GDI function, UpdateLayeredWindow.

    24bit Bitmap with alpha channel

    The most tricky part of creating the bitmap is finding a simple file format that has an embedded alpha channel.

    The selected file format for the first incarnation of this article was PSP (Paint Shop Pro™ from Jasc®), but now the recommended file format has been changed to PNG (Portable Network Graphics).

    For loading PNG files I use the paintlib library. This library can also load files from PCX, TGA and TIFF formats.

    This demo application does not use paintlib directly; instead it uses a paintlib wrapper dll, ImgDecoder.Dll.

    For loading PSP files I've created a function called LoadPSPFileToDIB(PSPLoader.h/cpp).

    UpdateLayeredWindow

    To use this function we must have a top-level window (in this sample this is implemented by the class CDummyDialog) with the extended style WS_EX_LAYERED set.

    Before we can pass the bitmap to the UpdateLayeredWindow function, we must pre-multiply the rgb channels with the alpha channel. For this you just have to call the PreMultiplyRGBChannels function (take a look at CPerpixelalphaDlg::DoLoadFile).

    From here on read the source code in CPerpixelalphaDlg::DoUpdateDummyDialog.

    Installing & Building

    1. Make sure you have the SDK for Windows® NT 5.0.
    2. Download and extract the source code of this article.
    3. Build and enjoy!

    If you want to build the ImgDecoder.Dll you also have to,

    1. Download paintlib and all the required libraries.
    2. Download the ImgDecoder project.
    3. Extract the ImgDecoder project to the paintlib library.
    4. Build the ImgDecoder project.
    5. Copy the resulting ImgDecoder.dll and ImgDecoder.lib to the bin directory of this article's demo application.

    License

    1. You must mention my name in your application documentation/help box, something like, Portions � 2001 by Rui Godinho Lopes <ruiglopes@yahoo.com>.
    2. I would appreciate it if you send me an email letting me know that you are using this code.
    3. I cannot be held responsible of any kind of data loss caused directly or indirectly by the use of this code - use it at your own risk.
    4. You cannot sell this code - this is free software.

    Don't forget if you have any constructive thoughts just email 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


    Member

    Occupation: Web Developer
    Location: Portugal Portugal

    Other popular GDI articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 96 (Total in Forum: 96) (Refresh)FirstPrevNext
    Generalbeginner code... Pinmemberkilt6:39 12 Oct '09  
    GeneralRe: beginner code... PinmemberApuhjee5:24 23 Oct '09  
    Generalgreat tutorial ! some questions about this still Pinmembernirishere1:21 5 Sep '09  
    GeneralHow about clean WinAPI? Pinmemberflaviusv11:16 12 Oct '08  
    GeneralHow can I draw text on the alpha window? PinmemberGreg Ellis11:04 24 Aug '08  
    GeneralRe: How can I draw text on the alpha window? PinmemberGreg Ellis6:41 27 Aug '08  
    GeneralHow to use control in Layered windows Pinmemberpherosiden19:29 29 Oct '07  
    QuestionUrgent (UNICODE) ! PinmemberMutant X12321:29 3 Sep '07  
    GeneralTrouble with headers PinmemberDelfistyaosani21:52 28 Jun '07  
    GeneralRe: Trouble with headers Pinmemberkr.kim22:35 10 May '09  
    GeneralRe: Trouble with headers PinmemberDelfistyaosani4:29 11 May '09  
    GeneralRe: Trouble with headers Pinmemberkr.kim8:29 11 May '09  
    Generalundeclared identifiers PinmemberDV649:09 13 Apr '07  
    GeneralMore Test Images Pinmemberninadpachpute23:05 12 Feb '07  
    JokeGR8 STUFF!!! PinmemberDieZeL0:09 26 Jul '06  
    GeneralHow to add control to the dialog? Pinmemberblackgole16:47 20 Jul '06  
    GeneralEfficency of layered windows Pinmemberjens pedersen4:40 9 Jun '06  
    QuestionWriting Text PinmemberMrBlob15:29 31 May '06  
    AnswerRe: Writing Text PinmemberManni Singh3:02 28 Mar '07  
    GeneralRe: Writing Text PinmemberGreg Ellis10:43 27 Aug '08  
    QuestionUpdateLayeredWindow Pinmembertoto777toto17:14 9 Apr '06  
    AnswerRe: UpdateLayeredWindow Pinmemberamit dedha7:42 28 Sep '06  
    GeneralDon't use this! PinmemberGeorge9876543216:23 3 Mar '06  
    GeneralRe: Don't use this! PinmemberRui Godinho Lopes8:27 3 Mar '06  
    GeneralRe: Don't use this! PinmemberGeorge9876543218:08 4 Mar '06  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 20 Apr 2001
    Editor: James Spibey
    Copyright 2001 by Rui Lopes
    Everything else Copyright © CodeProject, 1999-2009
    Web21 | Advertise on the Code Project