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);搜索ide

 

 

 

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

3        { orm

4             //建立圖象,保存未來截取的圖象
5             Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); blog

6             Graphics imgGraphics = Graphics.FromImage(image);string

7             //設置截屏區域 柯樂義
8             imgGraphics.CopyFromScreen(0, 0, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)); it

9             //保存
10           SaveImage(image); io

11 } class

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

15         { file

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         }

相關文章
相關標籤/搜索