一、函数输入
输入有两个,参数一:需要截图的容器控件,参数二:保存截图的绝对路径路径
<param name="control">控件名</param>
<param name="addrname">保存图片地址(绝对路径)</param>
二、函数输出
函数无反馈值,但会在指定路径下生成bmp格式的截图文件

三、使用示例
1、需要截图的范围是tablelayoutpanel1容器控件中的四个图表,放置到"c:\\users\\administrator\\documents\\123__s.bmp"路径下

2、将参数放入,调用函数
//capturecontrol(tablelayoutpanel1, "c:\\users\\administrator\\documents\\123__s.bmp"); capturecontrol(tablelayoutpanel1, picpath);
3、查看结果


函数源码如下:
/// <summary>
/// 截图指定控件内图像
/// </summary>
/// <param name="control">控件名</param>
/// <param name="addrname">保存图片地址(绝对路径)</param>
public void capturecontrol(control control, string addrname)
{
// 获取控件的位置和尺寸
rectangle bounds = control.bounds;
// 创建一个位图对象
bitmap bitmap = new bitmap(bounds.width, bounds.height);
// 将控件绘制到位图上
control.drawtobitmap(bitmap, new rectangle(0, 0, bounds.width, bounds.height));
//按指定名称存储到路径下
bitmap.save(addrname, system.drawing.imaging.imageformat.bmp);
}到此这篇关于c# winform截图指定控件范围内的图像的流程步骤的文章就介绍到这了,更多相关c# winform截图指定图像内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论