1.做path
string CurrentPath = Environment.CurrentDirectory;
string imageName = CurrentPath + @"\" + GetImageName();
private string GetImageName()
{
if (!File.Exists("Image"))
{
Directory.CreateDirectory("Image");
}
string time = DateTime.Now.ToString("hh-mm-ss");
return @"Image\" + time + ".bmp";
}
2.按需截图
private void Screenshot()
{
string CurrentPath = Environment.CurrentDirectory;
string imageName = CurrentPath + @“” + GetImageName();
//综下所诉,可以完成大部分截图需求,截图截不全跟分辨率有关
//这个很鸡肋,要pictureBox上有才行,要是有的话我直接Save了,干嘛还搞这些
//Bitmap bitmap = new Bitmap(this.Width,this.Height);
//pictureBox1.DrawToBitmap(bitmap, new Rectangle(0, panel1.Height, panel2.Width, panel2.Height));
//Image image = bitmap;
//image.Save(imageName);
//截图指定区域,这里是pictureBox1区域
//Image objImage = new Bitmap(this.Width, this.Height);
//Graphics gd = Graphics.FromImage(objImage);
//Point f = this.PointToScreen(new Point(panel2.Left, panel2.Top));//这个应该是距离窗口之间的距离
//gd.CopyFromScreen(f, new Point(0, 0), new Size(pictureBox1.Width, pictureBox1.Height));//起始一个point,target2个point,target的起始点定点为source
//objImage.Save(imageName);
//截全屏
//int x = Screen.AllScreens[0].Bounds.Size.Width;
//int y = Screen.AllScreens[0].Bounds.Size.Height;
//Image image = new Bitmap(x, y);
//Graphics g = Graphics.FromImage(image);
//g.CopyFromScreen(0,0, 0, 0, new Size(x, y));
//image.Save(imageName);
}