第二个屏幕的屏幕截图。

| 嗨,我正在开发一个程序,用户可以在其中截屏。用户可以选择是否要从屏幕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
,它为您提供了一系列屏幕。这些对象具有
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, 
        0, 
        0,
        screen.Bounds.Size,
        CopyPixelOperation.SourceCopy );
    // Save the screenshot
}
    
        使用
Screen.AllScreens
通过特定屏幕的
Bounds
属性检索坐标,并将其传递给
CopyFromScreen
。     

要回复问题请先登录注册