如何获取屏幕截图的预定义区域坐标值?

发布于 2024-11-08 20:01:34 字数 1007 浏览 4 评论 0原文

可能的重复:
.NET 等效的截图工具

我下面的代码正在截取整个屏幕的屏幕截图,但是我想截取预定义区域的屏幕截图。我更喜欢单击按钮,然后拖动并选择我想要抓取 x、y、destinationX、destinationY 值的区域。有人可以给我一个提示或示例如何做到这一点吗?

bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                           Screen.PrimaryScreen.Bounds.Height, 
                           PixelFormat.Format32bppArgb);

// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);

// Take the screenshot from the upper left corner to the right bottom corner                    
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                             Screen.PrimaryScreen.Bounds.Y,
                             0,
                             0,
                             Screen.PrimaryScreen.Bounds.Size,
                             CopyPixelOperation.SourceCopy);

Possible Duplicate:
.NET Equivalent of Snipping Tool

My code below is taking screenshot for the whole screen, but I would like to take a screenshot with a pre-defined region. I prefer to click on a button then drag and select the region I want to grab x, y, destinationX, destinationY value. Can someone give me a hint or sample how to do that?

bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                           Screen.PrimaryScreen.Bounds.Height, 
                           PixelFormat.Format32bppArgb);

// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);

// Take the screenshot from the upper left corner to the right bottom corner                    
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                             Screen.PrimaryScreen.Bounds.Y,
                             0,
                             0,
                             Screen.PrimaryScreen.Bounds.Size,
                             CopyPixelOperation.SourceCopy);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2024-11-15 20:01:34

我还没有真正做过太多位图/图形工作,但是您是否可以简单地不捕获 mouse_down 和 mouse_up 事件的 X,Y 坐标,然后在 CopyFromScreen 方法中使用这些坐标,

例如:

 private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        startX = e.X;
        startY = e.Y;
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
        endX = e.X;
        endY = e.Y;
    }

然后您可以做一些数学来确定传输区域的大小并将其输入到您的方法中。

I haven't really done much bitmap/graphics work but can you simply not capture the X,Y co-ordinates of the mouse_down and mouse_up events and then use those in your CopyFromScreen method

Something like:

 private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        startX = e.X;
        startY = e.Y;
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
        endX = e.X;
        endY = e.Y;
    }

You can then do a little math to determine the size of the area to transfer and feed that into your method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文