如何解决第二个屏幕的屏幕截图
| 嗨,我正在开发一个程序,用户可以在其中截屏。用户可以选择是否要从屏幕1,2,3或4截取屏幕截图。我知道如何从第一个屏幕截取第一张截屏,但是如何从屏幕2,3和4截取图像呢? 我从第一个屏幕获取屏幕截图的代码如下: private void btnScreenOne_Click(object sender,EventArgs e)
{
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0,bitmap.Size);
bitmap.Save(@\"C:\\Users\\kraqr\\Documents\\PrintScreens\\\" +
DateTime.Now.ToString(\"yyyy-MM-dd_HH-mm-ss\") + \" Screen1\" +
\".bmp\",ImageFormat.Bmp);
}
感谢答案。
解决方法
Screen
类具有静态属性AllScreens
,它为您提供了一系列屏幕。这些对象具有Bounds
属性,您可以肯定使用...
长话短说:您可以使用所需屏幕的大小来初始化位图(不要使用PrimaryScreen
,因为顾名思义,这只是主要的),然后将适当的边界传递给CopyFromScreen
。
, 使用Screen.AllScreens代替:
foreach ( Screen screen in Screen.AllScreens )
{
screenshot = new Bitmap( screen.Bounds.Width,screen.Bounds.Height,System.Drawing.Imaging.PixelFormat.Format32bppArgb );
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage( screenshot );
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(
screen.Bounds.X,screen.Bounds.Y,screen.Bounds.Size,CopyPixelOperation.SourceCopy );
// Save the screenshot
}
, 使用Screen.AllScreens
通过特定屏幕的Bounds
属性检索坐标,并将其传递给CopyFromScreen
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。