//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 }