捕获虚拟屏幕(所有显示器) [英] Capturing virtual screen (all monitors)

查看:132
本文介绍了捕获虚拟屏幕(所有显示器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让整个虚拟屏幕的截图。这意味着,不只是在主屏幕的图像,但连接到电脑的每个屏幕。



有没有办法做到这一点?我试着用这一点,但它没有工作:

 位图B =新位图(SystemInformation.VirtualScreen.Width,SystemInformation。 VirtualScreen.Height); 
图形G = Graphics.FromImage(B);
this.Size =新的大小(SystemInformation.VirtualScreen.Width,SystemInformation.VirtualScreen.Height);
g.CopyFromScreen(0,0,0,0,b.Size); // MSDN:


解决方案

文档说: Graphics.CopyFromScreen(的Int32,的Int32,的Int32, INT32,大小):执行颜色数据位块传输,对应像素的长方形,从屏幕到Graphics的绘图图面不过。虚拟屏幕不一定是矩形:想象两台显示器具有1920×1200和1280×1024的分辨率所以,你需要做的就是创建一个位图就像你,然后列举你的显示器和执行 CopyFromScreen()为他们每个人



修改如果,例如,你有两个显示器,具有1280×1024的分辨率站在一个的的离开 1920x1200的一个,那么前者的坐标是(-1280,0) - (0,1024)因此,你需要执行 memoryGraphics.CopyFromScreen( - 1280,0,0,0,S); 其中s是尺寸(1280,1024)。对于第二个你需要调用 memoryGraphics.CopyFromScreen(0,0,* 1280 *,0,S); 和s将是尺寸(1920,1200)
希望这有助于。


I am trying to get a screenshot of the whole virtual screen. This means, an image of not just the primary screen, but every screen connected to the computer.

Is there a way to do that? I tried using this, but it didn't work:

Bitmap b = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
Graphics g = Graphics.FromImage(b);
this.Size = new Size(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
g.CopyFromScreen(0, 0, 0, 0, b.Size);

解决方案

The documentation says: Graphics.CopyFromScreen(Int32, Int32, Int32, Int32, Size): Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics." But the virtual screen is not necessarily a rectangle: imagine two monitors with 1920x1200 and 1280x1024 resolutions. So what you need to do is create a bitmap like you do, then enumerate your monitors and execute CopyFromScreen() for each of them.

Edit: If, for instance, you have two monitors, the one having 1280x1024 resolution standing on the left of 1920x1200 one, then the coordinates of the former would be (-1280,0) - (0, 1024). Therefore you need to execute memoryGraphics.CopyFromScreen(-1280, 0, 0, 0, s); where s is the Size(1280,1024). For the second one you need to call memoryGraphics.CopyFromScreen(0, 0, *1280*, 0, s); and s would be the Size(1920, 1200). Hope this helps.

这篇关于捕获虚拟屏幕(所有显示器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆