Graphics.CopyFromScreen, certain pixel color is transparent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #1

    Graphics.CopyFromScreen, certain pixel color is transparent

    I'm not asking how to do anything, I just need to know why something is happening. I wrote a program that is very simple, it takes a screenshot of a user-defined portion of the screen. Up until now I hadn't noticed anything wrong with it at all (and I haven't made any changes to the code that actually takes the screenshot, so I just didn't actually notice it happening.)

    Earlier though, I was testing some things out and I took a screenshot and noticed a few pixels were white (or I thought they were white.) I opened the image in Photoshop and learned that the pixels were actually transparent. I thought that was weird, but ignored it. Then I took another screenshot (after my desktop background had changed to a different picture) and opened it up...there were even more transparent pixels. So I opened the screenshot and the original image in Photoshop and overlayed them on top of each other so that the transparent pixels matched up with the actual pixel color from the original, and I learned that the pixel color being made transparent is #0D0B0C, or Red 13, Green 11, and Blue 12.

    Now I'm not sure if this is just my computer, so I don't want to go potentially messing things up by just clearing the graphics object to that color before taking the screenshot. Is there any reason this would happen? I know that if I specify a location off-screen for the screenshot to be taken, it shows up as transparent, could it be that the area off-screen is actually set to that color?

    Anyway, I'd just like to know how I could fix this, without taking the easy-but-potentially-not-right Graphics.Clear( ) path.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Hmmm that is interesting. Do you have a Transparency key set on your form (or anywhere in your project)
    In early versions of .NET you could easily make custom shaped forms with the transparency key, when .net2.0 came out I seem to recall it getting a lot harder. Not sure I ever did get it correct.
    Perhaps there is something screwy in relation to that?

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      I do have a transparency key in my form. The form background is set to Maroon (an arbitrary color I chose) and the transparency key is set to the same color, so that certain parts of the form are transparent. Here are links to a build of my program and the source:

      Executable
      Source

      But the transparency key is set to maroon, completely different than the color that is being made transparent in my screenshots, and when the program takes the screenshot, it hides the form, so I don't think it can be that.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Hmm, i didn't have any trouble with invisible colors using your source code. But I only tried a few times.
        Couple of thoughts I had:
        *The issue could come about when saving as png?
        *The issue could be transfering pixel data as bytes from the screen buffer to the bitmap object. Is absolutly every option on the bitmap set correctly to match the format of the screen graphics? Is it always the same? i.e. what if the user is running at 16bit color and not 32bit?
        *Is there any corolation to the missing color's location and any part of either of your forms?

        Comment

        Working...