欢迎访问!
您的支持是我们不断前行的动力!

C#前台屏幕截图

通过控件截图,通过坐标截图,通过矩形截图,全屏截图及区域截图

/// <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;
}
赞(1) 打赏
转载请注明出处,未注明出处不得转载,蜘蛛侠 » C#前台屏幕截图
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

蜘蛛侠,您身边的爬虫专家!

觉得文章有用就打赏一下文章作者吧

支付宝扫一扫打赏

微信扫一扫打赏