CaptureScreen.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Imaging;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace BaseLib
  10. {
  11. class CaptureScreen
  12. {
  13. /// <summary>
  14. /// 对整个界面进行截图保存
  15. /// </summary>
  16. /// <param name="control"></param>
  17. /// <param name="strPath"></param>
  18. /// <param name="imageFormat"></param>
  19. public void SaveScreenShots(Control control, string strPath, ImageFormat imageFormat)
  20. {
  21. //获取整个屏幕图像,不包括任务栏
  22. Rectangle ScreenArea = Screen.GetWorkingArea(control);
  23. Bitmap bmp = new Bitmap(control.Width, control.Height);//实例化一个和窗体一样大的bitmap
  24. using (Graphics g = Graphics.FromImage(bmp))
  25. {
  26. g.CopyFromScreen(0, 0, 0, 0, new Size(ScreenArea.Width, ScreenArea.Height));
  27. //g.CopyFromScreen(0, 0, 0, 0, new Size(2560, 1440));
  28. //g.CopyFromScreen(pictureBox1.PointToScreen(Point.Empty), pictureBox1.PointToScreen(Point.Empty), pictureBox1.Size);//只保存某个控件Point.Empty
  29. }
  30. bmp.Save(strPath, imageFormat);
  31. }
  32. }
  33. }