C#实现屏幕指定区域截屏

            //string Opath = @"C:/Picture";
            //if (Opath.Substring(Opath.Length - 1, 1) != @"/")
               //Opath = Opath + @"/";
            //string photoname = DateTime.Now.Ticks.ToString();
            //string path1 = Opath + DateTime.Now.ToShortDateString();
            //if (!Directory.Exists(path1))
                //Directory.CreateDirectory(path1);搜索

1           //截取全屏图象
2         private void btnFullScreen_Click(object sender, EventArgs e)

3        {

4             //创建图象,保存将来截取的图象
5             Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

6             Graphics imgGraphics = Graphics.FromImage(image);

7             //设置截屏区域 柯乐义
8             imgGraphics.CopyFromScreen(0, 0, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));

9             //保存
10           SaveImage(image);

11 }

12
13 //保存图象文件
14         private void SaveImage(Image image)

15         {

16             if (saveFileDialog.ShowDialog(this) == DialogResult.OK)

17             {

18                 string fileName = saveFileDialog.FileName;

19                 string extension = Path.GetExtension(fileName);

20                 if (extension == ".jpg")

21                  {

22                       image.Save(fileName, ImageFormat.Jpeg);

23                   }

24                 else
25                  {

26                        image.Save(fileName, ImageFormat.Bmp);

27                  }

28            }

29         }

原文地址:https://www.cnblogs.com/jf-guo/p/6611070.html