1

I am using following code to capture desktop screenshot.it works fine on normal DPI machines. But with machines that have DPI setting higher then normal, part of the screen is not shown in the capture image.

After little research i came to know that i need to add below settings in application manifest file.

followed steps specified in this link configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting

But still problem persists. Capture screen not proper on High-DPI Machines.

Please guide me.What else need to done to overcome this.

<asmv3:application xmlns="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>



static Bitmap CaptureDesktop()
    {
        SIZE size;
        Bitmap printscreen = null;

        size.cx = Win32Stuff.GetSystemMetrics
                         (Win32Stuff.SM_CXSCREEN);

        size.cy = Win32Stuff.GetSystemMetrics
                  (Win32Stuff.SM_CYSCREEN);

        int width = size.cx; int height = size.cy;

        IntPtr hWnd = Win32Stuff.GetDesktopWindow();
        IntPtr hDC = Win32Stuff.GetDC(hWnd);
        if (hDC != IntPtr.Zero)
        {
            IntPtr hMemDC = GDIStuff.CreateCompatibleDC(hDC);
            if (hMemDC != IntPtr.Zero)
            {
                IntPtr m_HBitmap = GDIStuff.CreateCompatibleBitmap(hDC, width, height);
                if (m_HBitmap != IntPtr.Zero)
                {
                    IntPtr hOld = (IntPtr)GDIStuff.SelectObject(hMemDC, m_HBitmap);
                    GDIStuff.BitBlt(hMemDC, 0, 0, width, height, hDC, 0, 0, GDIStuff.SRCCOPY);
                    GDIStuff.SelectObject(hMemDC, hOld);
                    GDIStuff.DeleteDC(hMemDC);
                    printscreen = System.Drawing.Image.FromHbitmap(m_HBitmap);
                    GDIStuff.DeleteObject(m_HBitmap);
                }
            }
        }
        Win32Stuff.ReleaseDC(hWnd, hDC);

        return printscreen;
    }
Azar Shaikh
  • 445
  • 9
  • 26
  • There's an example of setting DPI awareness on [this MSDN page](https://msdn.microsoft.com/en-gb/C9488338-D863-45DF-B5CB-7ED9B869A5E2?f=255&MSPPError=-2147217396) which is different from yours - you have ` – stuartd Mar 29 '19 at 13:25
  • tried without asmv3 but same effect. i did not understand what is wrong.do i need to calculate height,width pragmatically considering scaling? – Azar Shaikh Mar 29 '19 at 13:27

0 Answers0