码迷,mamicode.com
首页 > Windows程序 > 详细

Winform 根据Point截图并保存到指定路径

时间:2014-08-13 12:36:36      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   http   color   os   io   文件   

bubuko.com,布布扣
 1 /// <summary>
 2         /// 获取图片流
 3         /// </summary>
 4         /// <param name="ImageXY">图片屏幕起始点</param>
 5         /// <param name="ImageSize">图片大小</param>
 6         /// <returns></returns>
 7         public string CutImage(Point ImageXY, Size ImageSize, string FilePath,string FileName)
 8         {
 9             int[] sCreem = { Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height };
10             Bitmap bmp = new Bitmap(sCreem[0], sCreem[1]);
11             Graphics g = Graphics.FromImage(bmp);
12             g.CopyFromScreen(0, 0, 0, 0, new Size(sCreem[0], sCreem[1]));
13             string FileNamePath = "";
14             try
15             {
16                 Rectangle rect = new Rectangle(ImageXY, ImageSize);
17                 if (!rect.IsEmpty)
18                 {
19                     Bitmap imgbmp = new Bitmap(rect.Width, rect.Height);
20                     imgbmp = bmp.Clone(rect, PixelFormat.Format32bppRgb);
21                     FileNamePath = ImageSave(imgbmp, FilePath, FileName);
22                 }
23                 return FileNamePath;
24             }
25             catch (Exception ex)
26             {
27                 throw ex;
28             }
29         }
30         /// <summary>
31         /// 保存截图
32         /// </summary>
33         /// <param name="bmp"></param>
34         public string ImageSave(Bitmap bmp,string FilePath,string FileName)
35         {
36             try
37             {
38                 SaveFileDialog save = new SaveFileDialog();
39                 if (!Directory.Exists(FilePath))//如果不存在就创建file文件夹
40                 {
41                     Directory.CreateDirectory(FilePath);//创建该文件夹
42                 }
43                 save.FileName = FilePath;
44                 bmp.Save(save.FileName + FileName + ".jpg", ImageFormat.Jpeg);
45                 return FilePath + FileName + ".jpg";
46             }
47             catch (Exception ex)
48             {
49                 throw ex;
50             }
51         }
ImageCut
bubuko.com,布布扣
1 cut.CutImage(PointToScreen(Control.Location), Control.Size, System.IO.Directory.GetCurrentDirectory() + "\\Image\\", FileName);
调用

 

Winform 根据Point截图并保存到指定路径,布布扣,bubuko.com

Winform 根据Point截图并保存到指定路径

标签:winform   style   blog   http   color   os   io   文件   

原文地址:http://www.cnblogs.com/pyffcwj/p/3909466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!