第二个屏幕的屏幕截图

本文关键字:屏幕截图 屏幕 第二个 | 更新日期: 2023-09-27 17:57:54

嗨,我正在开发一个用户可以截屏的程序。用户可以选择是从屏幕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, 0, 0, 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:

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, 
        0, 
        0,
        screen.Bounds.Size,
        CopyPixelOperation.SourceCopy );
    // Save the screenshot
}

Screen类有一个静态属性AllScreens,它为您提供了一组屏幕。这些对象具有Bounds属性,您肯定可以使用它。。。

长话短说:使用所需屏幕的大小初始化位图(不要使用PrimaryScreen,因为顾名思义,这只是主要的一个),然后将适当的边界传递给CopyFromScreen

使用Screen.AllScreens通过特定屏幕的Bounds属性检索坐标,并将其传递给CopyFromScreen