抓取屏幕或窗体并保存成图片
时间:2010-09-07 来源:明月幾時有
抓取屏幕:
rectangle r = system.windows.forms.screen.primaryscreen.bounds;
image img = new bitmap(r.width, r.height);
graphics g = graphics.fromimage(img);
g.copyfromscreen(new point(0, 0), new point(0, 0), new size(r.width, r.height));。
intptr dc = g.gethdc();
g.releasehdc(dc);
g.dispose();
img .save("c:a.jpg");
或
private static extern bool bitblt(intptr hdcdest,int nxdest,int nydest,int nwidth,int nheight,intptr hdcsrc,int nxsrc,int nysrc,int32 dwrop);
private image catchscreen()
{
bitmap bmpcatched = new bitmap(this.tablelayoutpanel1.width + 1, this.tablelayoutpanel1.height + 1);
graphics g = graphics.fromimage(bmpcatched);
system.drawing.rectangle rect = new system.drawing.rectangle(10, 10, 500, 400);
g.copyfromscreen(new point(this.left + this.tablelayoutpanel1.location.x + 7, this.tablelayoutpanel1.location.y + (panelregisted.height - tablelayoutpanel1.height) / 2 - 1), new point(0, 0), this.panelregisted.clientrectangle.size);
g.drawrectangle(new pen(color.black), 0, 0, bmpcatched.width - 1, bmpcatched.height - 1);
image image = bmpcatched;
return image;
}
保存窗体或控件:
Rectangle r = Screen.PrimaryScreen.Bounds;
Bitmap bmp = new Bitmap(r.Width,r.Height);
this.DrawToBitmap(bmp, r);
bmp.Save("d:/aa.jpg");
注:窗体及控件皆有DRAWTOBITMAP这个方法(FW2.0以上)。
- 系统休眠文件删除后果 如何删除计算机的休眠文件 2025-04-22
- 站群服务器是什么意思 站群服务器的作用 站群服务器和普通服务器的区别 2025-04-22
- jQuery插件有何作用 jQuery插件的使用方法 2025-04-22
- jQuery插件有哪些种类 简单的jQuery插件实例 2025-04-22
-