【问题标题】:How to take screenshot of complete desktop Windows c# [closed]如何截取完整桌面Windows c#的屏幕截图[关闭]
【发布时间】:2021-02-09 13:43:15
【问题描述】:

以下代码仅截取桌面窗口。我的期望是用任务栏和用户可见的所有内容截取屏幕截图。

任何帮助将不胜感激

''' {

       //Creating a new Bitmap object

      Bitmap captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);

   
     //Bitmap captureBitmap = new Bitmap(int width, int height, PixelFormat);

     //Creating a Rectangle object which will  

     //capture our Current Screen

     Rectangle captureRectangle = Screen.AllScreens[0].Bounds;



     //Creating a New Graphics Object

     Graphics captureGraphics = Graphics.FromImage(captureBitmap);



    //Copying Image from The Screen

    captureGraphics.CopyFromScreen(captureRectangle.Left,captureRectangle.Top,0,0,captureRectangle.Size);



    //Saving the Image File (I am here Saving it in My E drive).

    captureBitmap.Save(@"E:\Capture.jpg",ImageFormat.Jpeg);



    //Displaying the Successfull Result



    MessageBox.Show("Screen Captured");

}

'''

【问题讨论】:

  • 你必须改变位图 captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);到位图 captureBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);你的位图太小了
  • @Triims,我也尝试使用下面的代码。但我仍然没有得到任务栏 var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat。 Format32bppArgb);
  • 这很奇怪,我对其进行了测试,并通过更改该行对我有用。是否在该位置创建了文件?
  • 毫无疑问。阅读How to Ask

标签: c# c++ windows msdn


【解决方案1】:

这对你应该没问题,重复问题here

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多