要使用C#截取整个屏幕,你可以使用System.Drawing和System.Windows.Forms命名空间中的类
using System;using System.Drawing;using System.Windows.Forms;namespace ScreenCapture{ class Program { static void Main(string[] args) { // 获取屏幕分辨率 int screenWidth = Screen.PrimaryScreen.Bounds.Width; int screenHeight = Screen.PrimaryScreen.Bounds.Height; // 创建Bitmap对象来保存屏幕截图 using (Bitmap screenshot = new Bitmap(screenWidth, screenHeight)) { // 创建Graphics对象来绘制屏幕截图 using (Graphics graphics = Graphics.FromImage(screenshot)) { // 将屏幕内容复制到Graphics对象中 graphics.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight)); } // 保存屏幕截图为文件 string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\screenshot.png"; screenshot.Save(filePath); Console.WriteLine("屏幕截图已保存到:" + filePath); } } }}这段代码首先获取屏幕的分辨率,然后创建一个Bitmap对象来保存屏幕截图。接下来,它创建一个Graphics对象并使用CopyFromScreen方法将屏幕内容复制到Graphics对象中。最后,它将屏幕截图保存为一个PNG文件,并在控制台输出文件路径。




