C# 保存屏幕截图

时间:2024-01-01 23:33:27
            //屏幕宽
int iWidth = Screen.PrimaryScreen.Bounds.Width;
//屏幕高
int iHeight = Screen.PrimaryScreen.Bounds.Height;
//按照屏幕宽高创建位图
Image img = new Bitmap(iWidth, iHeight);
//从一个继承自Image类的对象中创建Graphics对象
Graphics gc = Graphics.FromImage(img);
//抓屏并拷贝到myimage里
gc.CopyFromScreen(new Point(, ), new Point(, ), new Size(iWidth, iHeight));
//this.BackgroundImage = img;
//保存位图
img.Save(@"D:\" + Guid.NewGuid().ToString() + ".jpg");