通过控件截图,通过坐标截图,通过矩形截图,全屏截图及区域截图
/// <summary> /// 获取指定控件屏幕图像,不包括任务栏 /// </summary> /// <param name="ctrl"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <param name="destinationX"></param> /// <param name="destinationY"></param> /// <returns></returns> public static Bitmap GetScreenByCtrl(Control ctrl, int startX = 0, int startY = 0, int destinationX = 0, int destinationY = 0) { Rectangle ScreenArea = Screen.GetWorkingArea(ctrl); Bitmap bmp = new Bitmap(ScreenArea.Width, ScreenArea.Height); using (Graphics g = Graphics.FromImage(bmp)) { //此处通过设置坐标及大小获得区域截图 g.CopyFromScreen(startX, startY, destinationX, destinationY, new Size(ScreenArea.Width, ScreenArea.Height)); } return bmp; } /// <summary> /// 获取指定控件屏幕图像,不包括任务栏 /// </summary> /// <param name="p"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <param name="destinationX"></param> /// <param name="destinationY"></param> /// <returns></returns> public static Bitmap GetScreenByPoint(Point p, int startX = 0, int startY = 0, int destinationX = 0, int destinationY = 0) { Rectangle ScreenArea = Screen.GetWorkingArea(p); Bitmap bmp = new Bitmap(ScreenArea.Width, ScreenArea.Height); using (Graphics g = Graphics.FromImage(bmp)) { //此处通过设置坐标及大小获得区域截图 g.CopyFromScreen(startX, startY, destinationX, destinationY, new Size(ScreenArea.Width, ScreenArea.Height)); } return bmp; } /// <summary> /// 获取指定控件屏幕图像,不包括任务栏 /// </summary> /// <param name="rect"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <param name="destinationX"></param> /// <param name="destinationY"></param> /// <returns></returns> public static Bitmap GetScreenByRect(Rectangle rect, int startX = 0, int startY = 0, int destinationX = 0, int destinationY = 0) { Rectangle ScreenArea = Screen.GetWorkingArea(rect); Bitmap bmp = new Bitmap(ScreenArea.Width, ScreenArea.Height); using (Graphics g = Graphics.FromImage(bmp)) { //此处通过设置坐标及大小获得区域截图 g.CopyFromScreen(startX, startY, destinationX, destinationY, new Size(ScreenArea.Width, ScreenArea.Height)); } return bmp; }
评论前必须登录!
注册