如何截取完整桌面Windows c#的屏幕截图[关闭]
Posted
技术标签:
【中文标题】如何截取完整桌面Windows c#的屏幕截图[关闭]【英文标题】:How to take screenshot of complete desktop Windows c# [closed] 【发布时间】: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); 这很奇怪,我对其进行了测试,并通过更改该行对我有用。是否在该位置创建了文件? ***.com/a/13228495/17034 毫无疑问。阅读How to Ask。 【参考方案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);
【讨论】:
以上是关于如何截取完整桌面Windows c#的屏幕截图[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
C#搞跨平台桌面UI,分别实现Windows,Mac,Linux屏幕截图