欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 截取屏幕

程序员文章站 2023-09-28 18:38:39
/// /// 截取屏幕 /// /// 起点X坐标 /// 起点Y坐标 /// 截取宽度 ///
/// <summary>
/// 截取屏幕
/// </summary>
/// <param name="x">起点x坐标</param>
/// <param name="y">起点y坐标</param>
/// <param name="width">截取宽度</param>
/// <param name="height">截取高度</param>
/// <returns></returns>
private void capturescreen(double x, double y, double width, double height)
{
    int ix = convert.toint32(x);
    int iy = convert.toint32(y);
    int iw = convert.toint32(width);
    int ih = convert.toint32(height);

    system.drawing.bitmap bitmap = new system.drawing.bitmap(iw, ih);
    system.drawing.graphics graphics = system.drawing.graphics.fromimage(bitmap);
    graphics.copyfromscreen(ix, iy, 0, 0, new system.drawing.size(iw, ih));
    graphics.dispose();
}