C# 使用两点捕捉屏幕截图

C# 使用两点捕捉屏幕截图,c#,screenshot,C#,Screenshot,我怎样才能捕捉到一个给出两点的截图,然后基本上创建一个矩形截图或其他什么 我用了这个: 但它似乎没有得到我想要的矩形截图,它占据了屏幕的一角 private void KListener_KeyDown(object sender, RawKeyEventArgs args) { if (args.Key.ToString() == "F5") { Program.FirstPos = System.Windows.Form

我怎样才能捕捉到一个给出两点的截图,然后基本上创建一个矩形截图或其他什么

我用了这个:

但它似乎没有得到我想要的矩形截图,它占据了屏幕的一角

    private void KListener_KeyDown(object sender, RawKeyEventArgs args)
    {
        if (args.Key.ToString() == "F5")
        {
            Program.FirstPos = System.Windows.Forms.Cursor.Position;
            System.Media.SystemSounds.Asterisk.Play();
        }
        else if (args.Key.ToString() == "F6")
        {
            Program.SecondPos = System.Windows.Forms.Cursor.Position;
            System.Media.SystemSounds.Asterisk.Play();
        }
    }

    public Bitmap CaptureScreen()
    {
        RectangleF rect2 = GetRectangle(Program.FirstPos, Program.SecondPos);
        var image = new Bitmap((int)rect2.Width, (int)rect2.Height, PixelFormat.Format24bppRgb);
        var gfx = Graphics.FromImage(image);
        gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
        image.Save("C:\\Users\\DreTaX\\Documents\\teszt", ImageFormat.Jpeg);
        return image;
    }

CopyFromScreen(rect2.Left,rect2.Top,0,0,image.Size,CopyPixelOperation.SourceCopy)

你有没有考虑过坐标是基于屏幕左上角的。此外,向我们展示您迄今为止所写的内容将增加您获得帮助的机会。我所做的就是保存两个点(这两个点不同,我测试过了),然后使用该方法生成一个图像。不要认为这会改变任何东西,但您的图像变量是位图,所以它可以是“位图图像=…”,而gfx是图形类型,所以它可以是“Graphics gfx=…”,在运行代码时没有理由使用var。设置rect2时,矩形位置的值会得到什么?gfx.CopyFromScreen(rect2.Left、rect2.Top、0、0、image.Size、CopyPixelOperation.SourceCopy);请看这里@Jacobr365,我是否使用内置类型根本不重要。我会马上检查一下。顺便说一句,这是我得到的图像:所以第二个位置是完美的,但不知怎么的,第一个坐标颠倒了。它在反射