<p> /// <summary>
/// 屏幕截图
/// </summary>
/// <param name="start">截屏相对于屏幕左上角点位置</param>
/// <param name="width">截取宽度</param>
/// <param name="height">截取高度</param>
/// <param name="name"></param>
public static void Screenshot(Point start, int width, int height,ref string name)
{
//判断指定文件夹是否存在,若不存在,重新创建,在该文件架下面创建
System.IO.DirectoryInfo newInfo = new System.IO.DirectoryInfo(System.Environment.CurrentDirectory + @"\data\RegionChangeAnalysis\Pictures\");
if (newInfo.Exists == false)
{
newInfo.Create();
}</p><p> <strong><span style="font-size:14px;color:#ff0000;">var bitmap = new Bitmap(width, height);
var g = Graphics.FromImage(bitmap);
g.CopyFromScreen(start, new Point(0, 0), bitmap.Size);</span></strong></p><p> ///时间作为保存文档名
string datetime = DateTime.Now.ToString();
name = "";
for (int i = 0; i < datetime.Length; i++)
{
if (datetime.ElementAt(i) >= 48 && datetime.ElementAt(i) <= 57)
{
name += datetime.ElementAt(i);
}
}
bitmap.Save(System.Environment.CurrentDirectory + @"\data\RegionChangeAnalysis\Pictures\"+name+".png");
// return bitmap;
}</p>
C#图片截屏
最新推荐文章于 2023-04-18 22:30:48 发布