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. Visual Basic
  4. Odd Transparency behavior in VB.Net Panel

Odd Transparency behavior in VB.Net Panel

Scheduled Pinned Locked Moved Visual Basic
graphicsquestioncsharpcom
17 Posts 3 Posters 4 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.
  • D Dave Kreskowiak

    It could also be in the image itself if it was created with antialiasing turned on.

    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
    Dave Kreskowiak

    P Offline
    P Offline
    Peter R Fletcher
    wrote on last edited by
    #8

    Since writing my last message, I 'un-antialiased' the source image and tried again. Even though there are only three colors of pixels in the new source image (pure black, pure white, and the very dark gray used for the area to be rendered as transparent), the panel appears exactly the same when displayed on the desktop - with the thin green 'halo' round the clock. The new source image can be found here. It really does look as if the false color aliasing is happening when the image is created/initialized.

    D 1 Reply Last reply
    0
    • P Peter R Fletcher

      Yes. I was reusing old code which allowed color images. I wasn't the original author, so I didn't change anything that I didn't think absolutely had to be changed, and I wasn't sure whether any of the other reused code implicitly assumed the specified format. Indeed, experimentation since you raised the issue showed that using other formats (including indexed and grayscale ones) does cause other problems.

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

      In general, Windows (10) recommends against bit maps because they don't scale well. Use (font) icons and vector graphics. Segoe UI MDL2 assets can be overlayed, reversed and rotated. The .NET shape classess provide circles, polygons, etc. In your case, I would try overlaying the outter problem area with an ellipse / circle (black stroke, transparent fill) for a quick fix.

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      P 1 Reply Last reply
      0
      • L Lost User

        In general, Windows (10) recommends against bit maps because they don't scale well. Use (font) icons and vector graphics. Segoe UI MDL2 assets can be overlayed, reversed and rotated. The .NET shape classess provide circles, polygons, etc. In your case, I would try overlaying the outter problem area with an ellipse / circle (black stroke, transparent fill) for a quick fix.

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        P Offline
        P Offline
        Peter R Fletcher
        wrote on last edited by
        #10

        Well, that was very interesting! Doing as you suggested does not solve the problem. If you use a sensible sized pen (fairly small), nothing visible happens, and the 'halo' looks just as before, though there is a suggestion of it disappearing at the points where the drawn circle overlaps the edges of the original image (the top, bottom, and two sides). If you use a thicker pen, it is more obvious that the 'halo' is gone at the overlapped edges, but it is just pushed out to the edge of the drawn circle over the rest of the rendered image - it still always appears where a 'transparent' pixel was adjacent to one of another color, whether that pixel was part of the original bitmap or subsequently drawn on the Graphic. Presumably, therefore, it is an artefact of the [Bitmap].MakeTransparent() Function, but I have no idea why it has not (as far as I can tell) been described before Parenthetically, I now see that that function forces the Bitmap on which it is invoked to 32bppRgb mode, since that format has the alpha channel which it needs, so any attempt to use a different format would be pointless.

        L 1 Reply Last reply
        0
        • P Peter R Fletcher

          Since writing my last message, I 'un-antialiased' the source image and tried again. Even though there are only three colors of pixels in the new source image (pure black, pure white, and the very dark gray used for the area to be rendered as transparent), the panel appears exactly the same when displayed on the desktop - with the thin green 'halo' round the clock. The new source image can be found here. It really does look as if the false color aliasing is happening when the image is created/initialized.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #11

          I did something similar, though not transparent, a couple decades ago. Instead of using an image like that, I just drew the entire clock face when needed.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          P 1 Reply Last reply
          0
          • D Dave Kreskowiak

            I did something similar, though not transparent, a couple decades ago. Instead of using an image like that, I just drew the entire clock face when needed.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            P Offline
            P Offline
            Peter R Fletcher
            wrote on last edited by
            #12

            Since the clock face is invariant, it seemed to me to make sense to use a static image. My other experiments, described in the other 'branch' of this thread, would also suggest that your approach would not solve the haloing problem with transparency.

            D 1 Reply Last reply
            0
            • P Peter R Fletcher

              Since the clock face is invariant, it seemed to me to make sense to use a static image. My other experiments, described in the other 'branch' of this thread, would also suggest that your approach would not solve the haloing problem with transparency.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #13

              I think no matter what color you pick for the chroma key, you're going to have the same problem. It comes down to the key color you pick isn't the resulting key color when the black of the clock face and the key color are blended together. I don't think there's going to be any solution to the problem while using a chroma key.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              P 1 Reply Last reply
              0
              • P Peter R Fletcher

                Well, that was very interesting! Doing as you suggested does not solve the problem. If you use a sensible sized pen (fairly small), nothing visible happens, and the 'halo' looks just as before, though there is a suggestion of it disappearing at the points where the drawn circle overlaps the edges of the original image (the top, bottom, and two sides). If you use a thicker pen, it is more obvious that the 'halo' is gone at the overlapped edges, but it is just pushed out to the edge of the drawn circle over the rest of the rendered image - it still always appears where a 'transparent' pixel was adjacent to one of another color, whether that pixel was part of the original bitmap or subsequently drawn on the Graphic. Presumably, therefore, it is an artefact of the [Bitmap].MakeTransparent() Function, but I have no idea why it has not (as far as I can tell) been described before Parenthetically, I now see that that function forces the Bitmap on which it is invoked to 32bppRgb mode, since that format has the alpha channel which it needs, so any attempt to use a different format would be pointless.

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

                I think your problem is part of Windows Forms. I do a lot of graphics in UWP and WPF and never have any issues I can't overcome. e.g. WPF and snap to pixels:

                Quote:

                You can set this property to true on your root element to enable pixel snap rendering throughout the UI. For devices operating at greater than 96 dots per inch (dpi), pixel snap rendering can minimize anti-aliasing visual artifacts in the vicinity of single-unit solid lines.

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  I think no matter what color you pick for the chroma key, you're going to have the same problem. It comes down to the key color you pick isn't the resulting key color when the black of the clock face and the key color are blended together. I don't think there's going to be any solution to the problem while using a chroma key.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  P Offline
                  P Offline
                  Peter R Fletcher
                  wrote on last edited by
                  #15

                  I am not sure what you mean by 'chroma key' in this context. The placeholder 'color' I am using for the transparent area is a very dark gray - the entire palette of the image is grayscale. If you blend black, white, and a pure grey in any proportions, you shouldn't get bright green!

                  D 1 Reply Last reply
                  0
                  • P Peter R Fletcher

                    I am not sure what you mean by 'chroma key' in this context. The placeholder 'color' I am using for the transparent area is a very dark gray - the entire palette of the image is grayscale. If you blend black, white, and a pure grey in any proportions, you shouldn't get bright green!

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #16

                    The "chroma key" is the color chosen to be replaced by "transparent", or "green screen".

                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                    Dave Kreskowiak

                    P 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      The "chroma key" is the color chosen to be replaced by "transparent", or "green screen".

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      P Offline
                      P Offline
                      Peter R Fletcher
                      wrote on last edited by
                      #17

                      That's what I thought you meant, hence my comment that blending white, black, and gray shouldn't give you green!

                      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