屏幕捕捉程序拷贝超过选定区域

问题描述 投票:0回答:1

我在创造与C#中的屏幕捕捉程序,随后休Collingbourne程序。不过,我注意到一对夫妇奇怪的物品,和我是否使用他创建的程序或修改我的程序做相同。具体来说,我创建了一个打开一个窗口,让您捕捉区域的程序。我认为这与我的电脑上开庭的事,但需要知道如何预见和解决这个问题,如果别人要使用我的屏幕捕捉程序!如果我的Windows 10的显示器设置为100%,我得到比所选窗口多一点,如果我设置显示125%文本,然后我得到了很多的选择区域。在默认大小离开我应该是555,484的尺寸。但我捕捉大得多。

public partial class Form1 : Form
{
    //https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();
    [DllImport("user32.dll")]
    private static extern IntPtr GetDesktopWindow();
    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle lpRect);

    //ICON info
    //https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getcursorinfo
    [DllImport("user32.dll")]
    private static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);
    [DllImport("user32.dll")]
    private static extern bool GetCursorInfo(out CURSORINFO pci);


    public struct POINT
    {
        public Int32 x;
        public Int32 y;
    }

    public struct ICONINFO
    {
        public bool fIcon;
        public Int32 xHotspot;
        public Int32 yHotspot;
        public IntPtr hbmMask;
        public IntPtr hbmColor;
    }

    public struct CURSORINFO
    {
        public Int32 cbSize;
        public Int32 flags;
        public IntPtr hCursor;
        public Point ptScreenPos;
    }

    GrabRegionForm grabForm;

    public void GrabRect(Rectangle rect)
    {
        int rectWidth = rect.Width - rect.Left;
        int rectHeight = rect.Height - rect.Top;
        Bitmap bm = new Bitmap(rectWidth, rectHeight);
        Graphics g = Graphics.FromImage(bm);
        g.CopyFromScreen(rect.Left, rect.Top, 0, 0, new Size(rectWidth, rectHeight));
        DrawMousePointer(g, Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top);
        this.pb_screengrab.Image = bm;
        Clipboard.SetImage(bm);
    }
}

public partial class GrabRegionForm : Form
{
    public Rectangle formRect;
    private Form1 mainForm;
    [DllImport("user32.dll")]
    public static extern bool ReleaseCapture();
    [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    private void buttonOK_Click(object sender, EventArgs e)
    {
        formRect = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
        this.Hide();
        mainForm.GrabRect(formRect);
        Close();
    }
}

ScreenGrab with Display at 100%

ScreenGrab with Display at 125%

Area showing capture window

Area Actually Captured

c# winforms screenshot dpi
1个回答
0
投票

如果使用早于4.7,而不是窗户10跟随吉米的例子,并确保您注销并重新进入Windows。

从吉米https://stackoverflow.com/users/7444103/jimi如何配置一个应用程序的机器上具有高DPI设置How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?正常运行

从吉米https://stackoverflow.com/users/7444103/jimi使用多台监视器Using SetWindowPos with multiple monitors SetWindowPos

如果我定位我的Windows 10应用程序只有现在是难以置信的简单。微软使其更容易与如果使用的是Windows 10使用4.7更改DPI设置。

https://docs.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms

声明兼容性与Windows 10,然后添加以下到app.manifest文件中的XML的表彰为Windows 10兼容之下。

supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"

启用app.config文件每个监视器DPI意识。 Windows窗体引入了新的元素,以支持新的功能和自定义开始加入与.NET Framework 4.7。要充分利用支持高DPI的新功能,添加以下到您的应用程序配置文件。

去为System.Windows.Forms.ApplicationConfigurationSection的XML行

add key="DpiAwareness" value="PerMonitorV2"
© www.soinside.com 2019 - 2024. All rights reserved.