using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BaseLib { class CaptureScreen { /// /// 对整个界面进行截图保存 /// /// /// /// public void SaveScreenShots(Control control, string strPath, ImageFormat imageFormat) { //获取整个屏幕图像,不包括任务栏 Rectangle ScreenArea = Screen.GetWorkingArea(control); Bitmap bmp = new Bitmap(control.Width, control.Height);//实例化一个和窗体一样大的bitmap using (Graphics g = Graphics.FromImage(bmp)) { g.CopyFromScreen(0, 0, 0, 0, new Size(ScreenArea.Width, ScreenArea.Height)); //g.CopyFromScreen(0, 0, 0, 0, new Size(2560, 1440)); //g.CopyFromScreen(pictureBox1.PointToScreen(Point.Empty), pictureBox1.PointToScreen(Point.Empty), pictureBox1.Size);//只保存某个控件Point.Empty } bmp.Save(strPath, imageFormat); } } }