【发布时间】: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。