1 ///2 /// 获取图片流 3 /// 4 /// 图片屏幕起始点 5 /// 图片大小 6 ///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 try15 {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 /// 31 /// 保存截图32 /// 33 /// 34 public string ImageSave(Bitmap bmp,string FilePath,string FileName)35 {36 try37 {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 }
1 cut.CutImage(PointToScreen(Control.Location), Control.Size, System.IO.Directory.GetCurrentDirectory() + "\\Image\\", FileName);