1

So I've been trying to get the screenshot of my current active window and I'm following the answers given in Capture screenshot of active window?

This is what I expect to see

form

But for some reason I get the following screenshot

actual result

This is how I get the Bitmap:

public Bitmap Capture()
{
    Rectangle bounds;

    var foregroundWindowsHandle = GetForegroundWindow();
    var rect = new Rect();            
    GetWindowRect(foregroundWindowsHandle, ref rect);

    bounds = new Rectangle(rect.Left, rect.Top, (rect.Right - rect.Left), (rect.Bottom - rect.Top));

    var result = new Bitmap(bounds.Width, bounds.Height);

    using (var g = Graphics.FromImage(result))
    {
        g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
    }

    return result;
}

Where I later save I to a jpeg file

I tried all of the methods proposed in the mentioned link

What am I missing here?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Guy G
  • 13
  • 1
  • 7
  • Read the note here: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103). Stop by the *Important note about Dpi Awareness*. Make your app DpiAware (yes, it needs some work) to solve the problem. – Jimi Apr 26 '20 at 00:47

0 Answers0