如何获取屏幕截图的预定义区域坐标值?
可能的重复:
.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有真正做过太多位图/图形工作,但是您是否可以简单地不捕获 mouse_down 和 mouse_up 事件的 X,Y 坐标,然后在 CopyFromScreen 方法中使用这些坐标,
例如:
然后您可以做一些数学来确定传输区域的大小并将其输入到您的方法中。
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:
You can then do a little math to determine the size of the area to transfer and feed that into your method.