主WPF窗口下的第二个显示器/电视截图 [英] Screenshot of the main WPF window under second monitor/TV

查看:414
本文介绍了主WPF窗口下的第二个显示器/电视截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的第二个显示器上,有时在电脑的主监视器应用程序。

我怎样才能得到第二个显示器的屏幕截图?

下面code没有第二个显示器工作...

 显卡GFX;
BMP位图=新位图(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
GFX = Graphics.FromImage(BMP);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy);

MemoryStream的毫秒=新的MemoryStream();
bmp.Save(MS,ImageFormat.Jpeg);
byte []的位图数据= ms.ToArray();
 

解决方案

使用 Screen.AllScreens [1] .Bounds 的isntead Screen.PrimaryScreen .Bounds

或者更可靠拿到的第一个非主屏幕。

  VAR secondScreen = Screen.AllScreens.Where(屏幕=>!screen.Primary).FirstOrDefault();
 

检查 secondScreen == NULL 要知道,如果你有一个secondScreen。

修改
您可能也有兴趣 Screen.FromControl ,让屏幕应用程序正在运行。

I use my application on the second monitor and sometimes at the primary monitor of the computer.

How I can get screenshot of the second monitor?

The following code doesn't work for the second monitor...

Graphics gfx;
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
gfx = Graphics.FromImage(bmp);
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
byte[] bitmapData = ms.ToArray();

解决方案

Use Screen.AllScreens[1].Bounds isntead of Screen.PrimaryScreen.Bounds.

Or more reliable to get the first non Primary Screen.

var secondScreen = Screen.AllScreens.Where(screen => !screen.Primary).FirstOrDefault();

check for secondScreen == null to know if you have a secondScreen.

Edit:
You might also be interested in Screen.FromControl that gives the screen that the application is currently running on.

这篇关于主WPF窗口下的第二个显示器/电视截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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