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

问题描述:

可能重复:
.NET Equivalent of Snipping Tool如何抓取屏幕截图的预定义区域坐标值?

我下面的代码正在为整个屏幕截图,但我想采取截图与预先设定的区域。我更喜欢点击一个按钮,然后拖动并选择我想抓取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); 

我还没有真正做了很多位图/图形工作,但你能不能简单地捕捉到X,该MOUSE_DOWN的Y坐标和MOUSE_UP事件,然后使用这些在你的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; 
    } 

然后,您可以做一些小算术以确定要传输的区域的大小,并将其填充到您的方法中。