在某窗体或控件上抓图的源码
求一个在某窗体或控件上抓图的源码
论坛里不少源码是介绍怎样在屏幕上截图,比如仿QQ抓图的工具。
请问高手如何实现在一个窗体或者控件上抓图?比如百度地图的截图功能,先谢过!
源码最好是c#。
------解决思路----------------------
句柄截图即可。
------解决思路----------------------
这是截屏代码,要实现你说那些功能,自己做逻辑处理
论坛里不少源码是介绍怎样在屏幕上截图,比如仿QQ抓图的工具。
请问高手如何实现在一个窗体或者控件上抓图?比如百度地图的截图功能,先谢过!
源码最好是c#。
------解决思路----------------------
句柄截图即可。
------解决思路----------------------
const int SRCCOPY = 0xcc0020;
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int BitBlt(HandleRef hdcDst, int x, int y, int nWidth, int nHeight, HandleRef hdcSrc, int xSrc, int ySrc, int dwRop);
// 被截屏的控件句柄(this则是截当前窗体)
Graphics gForm = this.CreateGraphics();
IntPtr hdcForm = gForm.GetHdc();
HandleRef hdcRefForm = new HandleRef(null, hdcForm);
// 截图保存图片
Bitmap bmp = new Bitmap(this.Width, this.Height);
Graphics gBmp = Graphics.FromImage(bmp);
IntPtr hdcBmp = gBmp.GetHdc();
HandleRef hdcRefBmp = new HandleRef(null, hdcBmp);
// 截图
BitBlt(hdcRefBmp, 0, 0, this.Width, this.Height, hdcRefForm, 0, 0, SRCCOPY);
// 释放
gForm.ReleaseHdc(hdcForm);
gForm.Dispose ();
gBmp.ReleaseHdc(hdcBmp);
gBmp.Dispose ();
//保存
bmp.Save("/Users/leendx/Documents/test_output/1.bmp", ImageFormat.Bmp);
这是截屏代码,要实现你说那些功能,自己做逻辑处理