Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Displaying a 32bit bitmap with Alpha channel transparency

Displaying a 32bit bitmap with Alpha channel transparency

Scheduled Pinned Locked Moved C#
graphicsquestion
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ __John_

    Hi, I want to display(on a Form) a 32bit bitmap with Alpha channel transparency, so thet the transparency is honoured. I have tried a Picture control but it ignores the Alpha channel. Any ideas? Thanks - John

    “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #2

    What format is the image? As far as I'm aware a bitmap doesn't support the alpha channel in Windows, but you would rather manage it using a chroma key (that's where you choose one colour as being transparent). If it is a bitmap, then you might want to try out the code sample here[^] If you are using a PNG (for instance), then just set the appropriate PixelFormat, i.e. PixelFormat.Format32bppArgb;

    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

    _ S 2 Replies Last reply
    0
    • P Pete OHanlon

      What format is the image? As far as I'm aware a bitmap doesn't support the alpha channel in Windows, but you would rather manage it using a chroma key (that's where you choose one colour as being transparent). If it is a bitmap, then you might want to try out the code sample here[^] If you are using a PNG (for instance), then just set the appropriate PixelFormat, i.e. PixelFormat.Format32bppArgb;

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      _ Offline
      _ Offline
      __John_
      wrote on last edited by
      #3

      Thanks Pete, The image format is 32bit bmp. But I could easly change it to png using Gimp. Where does PixelFormat come from? I checked Image.PixelFormat on msdn... http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.DRAWING.IMAGE.PIXELFORMAT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true[^] All it does is show how to call ToString() on it (why do they bother). Thanks - John

      “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

      P L 2 Replies Last reply
      0
      • _ __John_

        Thanks Pete, The image format is 32bit bmp. But I could easly change it to png using Gimp. Where does PixelFormat come from? I checked Image.PixelFormat on msdn... http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.DRAWING.IMAGE.PIXELFORMAT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true[^] All it does is show how to call ToString() on it (why do they bother). Thanks - John

        “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #4

        PixelFormat is an enumeration[^].

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        _ 1 Reply Last reply
        0
        • _ __John_

          Thanks Pete, The image format is 32bit bmp. But I could easly change it to png using Gimp. Where does PixelFormat come from? I checked Image.PixelFormat on msdn... http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.DRAWING.IMAGE.PIXELFORMAT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true[^] All it does is show how to call ToString() on it (why do they bother). Thanks - John

          “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          Just FYI, 32bit BMP is almost universally unsupported. Even by image manipulation programs.

          _ 1 Reply Last reply
          0
          • P Pete OHanlon

            PixelFormat is an enumeration[^].

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            _ Offline
            _ Offline
            __John_
            wrote on last edited by
            #6

            Image.PixelFormat

            Has no Set method it can only be read.

            “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

            1 Reply Last reply
            0
            • L Lost User

              Just FYI, 32bit BMP is almost universally unsupported. Even by image manipulation programs.

              _ Offline
              _ Offline
              __John_
              wrote on last edited by
              #7

              Yeh, I see what you mean. You would think by now that there would be a standard way of handling transparency, but ther isn't. its all over the place, Alpha channels, transparency masks of every posible value ever known, what a can of worms it is.

              “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

              L B 2 Replies Last reply
              0
              • _ __John_

                Yeh, I see what you mean. You would think by now that there would be a standard way of handling transparency, but ther isn't. its all over the place, Alpha channels, transparency masks of every posible value ever known, what a can of worms it is.

                “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                Transparency is a lot easier in WPF than in Windows Forms, would it be possible to convert the program to WPF?

                1 Reply Last reply
                0
                • P Pete OHanlon

                  What format is the image? As far as I'm aware a bitmap doesn't support the alpha channel in Windows, but you would rather manage it using a chroma key (that's where you choose one colour as being transparent). If it is a bitmap, then you might want to try out the code sample here[^] If you are using a PNG (for instance), then just set the appropriate PixelFormat, i.e. PixelFormat.Format32bppArgb;

                  *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  S Offline
                  S Offline
                  SledgeHammer01
                  wrote on last edited by
                  #9

                  Pete O'Hanlon wrote:

                  As far as I'm aware a bitmap doesn't support the alpha channel in Windows

                  Since when? Bitmaps (BMP) have supported the alpha channel for probably close to a decade or more.

                  P 1 Reply Last reply
                  0
                  • S SledgeHammer01

                    Pete O'Hanlon wrote:

                    As far as I'm aware a bitmap doesn't support the alpha channel in Windows

                    Since when? Bitmaps (BMP) have supported the alpha channel for probably close to a decade or more.

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #10

                    Note the careful use of Windows here - it's not the problem with Bitmaps, it's a problem with Windows.

                    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                    1 Reply Last reply
                    0
                    • _ __John_

                      Yeh, I see what you mean. You would think by now that there would be a standard way of handling transparency, but ther isn't. its all over the place, Alpha channels, transparency masks of every posible value ever known, what a can of worms it is.

                      “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford

                      B Offline
                      B Offline
                      BillWoodruff
                      wrote on last edited by
                      #11

                      __John_ wrote:

                      You would think by now that there would be a standard way of handling transparency

                      I'm glad to see there are optimists still afloat ! :) imho, using PNG's with transparency has become a standard: they work in .NET, they work on the web. best, Bill

                      "The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups