Missing Pixels from ScreenShot RRS feed

  • Question

  • I have a VS2017 C# program that captures a screen shot of a Windows Form application that uses a webbrowser control.  I saved the screenshot to a bmp and file.  When I use .GetPixel() to retrieve the color from the bmp data, I can only retrieve the background color property and not the webrowser control color even though the webbrowser displays when I look at the file.  It is as if the webbrowser image is saved in a layer in the bmp data that the .GetPixel() is missing.  Here is my code:

    private void btnScreenCapture_Click(object sender, EventArgs e)
                int red = 0;
                int green = 0;
                int blue = 0;
                int alpha = 0;
                Color p1 = new Color();
                Point screen_pt = new Point(0, 0);
                Point client_pt = new Point(0, 0);
                client_pt.X = 1;
                client_pt.Y = 1;
                screen_pt = wbrGeneral.PointToScreen(client_pt);
                var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                // Create a graphics object from the bitmap.
                var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                // Take the screenshot from the upper left corner to the right bottom corner.
                // Save the screenshot to the specified path that the user has chosen.
                bmpScreenshot.Save(@"C:/Temp/Screenshot.png", ImageFormat.Png);
                Point bmpPt = new Point(screen_pt.X, screen_pt.Y);
                for (int p = 1; p <860; p++)
                    bmpPt.X = 225;
                    bmpPt.Y = 0 + p;
                    p1 = bmpScreenshot.GetPixel(bmpPt.X, bmpPt.Y);
                    red = p1.R;
                    green = p1.G;
                    blue = p1.B;
                    alpha = p1.A;
                    lstScreen.Items.Add("(" + bmpPt.ToString() + ")" + "A=" + Convert.ToString(alpha) + " R=" + Convert.ToString(red) + " G=" + Convert.ToString(green) + " B=" + Convert.ToString(blue));


    When I inspect the color content of the lstScreen only the form's background color are saved to the screenshot.  It is as if the Webbrowser control is not even on the screen.

    Where is the Webbrowser display data retained in the bmp?  It is clearly there as it shows up when ever I open the file.

    Monday, April 23, 2018 3:52 AM

All replies

  • You are looking at a vertical line of pixels that is 225 pixels from the left edge of the screen.  How do you know that your window actually lives at X=225?

    Also, you need to remember that coordinates in Windows start from 0.  Your code suggests you might think they start from 1.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Monday, April 23, 2018 5:47 AM
  • Hello Alex,

    The file you saved is entire windows screen rather than webbrowser content, which means you can't know the specific locations of which. When you iterate the pixels how do you know that the scope is you want. Maybe you could save only screen shot of webbrowser content as below code and then loop it.

      Bitmap bitmap = new Bitmap(webBrowser1.Width, webBrowser1.Height);
      webBrowser1.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height));

    Best Regards,

    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, April 24, 2018 6:07 AM