Search code examples
c#wpfscreenshot

C# Screen Capture Ignoring Application


I'm currently on an library which has one function that requires that I capture the screen, INCLUDING the application wpf application that spawned it. The problem that occurs is that when the function executes (code at the bottom) the image that's saved ignores the application, e.g. it's icon is still on the taskbar, but it's not visible, the other windows that were "behind it" are however. I've been unable to change it so that the app itself would be front in center in the image even though it should be regardless.

using (Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
        {
            Thread.Sleep(1000);
            using (Graphics graphics = Graphics.FromImage(printscreen as Image))
            {
                graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
                printscreen.Save(FilePath, ImageFormat.Jpeg);
            }
        }

Any assistance is most appreciated.

Edit: Well... that went oddly, after restarting the computer the code was working perfectly, and all of my compatriots have it working on their machines as well, I'm unsure what was creating the problem earlier but it seems to no longer exist.


Solution

  • Well... that went oddly, after restarting the computer the code was working perfectly, and all of my compatriots have it working on their machines as well, I'm unsure what was creating the problem earlier but it seems to no longer exist.