此文记录的是窗体截图工具类。
/*** 窗体图像操作类 Austin Liu 刘恒辉 Project Manager and Software Designer E-Mail: lzhdim@163.com Blog: http://lzhdim.cnblogs.com Date: 2024-01-15 15:18:00 使用方法: Image image = WindowImageUtil.GetWindowImage(this.Handle); 注意: 截图的包括遮挡窗口,最小化窗口。 ***/ namespace Lzhdim.LPF.Utility { using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; /// <summary> /// 窗体图像操作类 /// </summary> public class WindowImageUtil { /// <summary> /// 获取窗体当前截图 /// </summary> /// <param name="windownHandle"></param> /// <returns></returns> public static Image GetWindowImage(IntPtr windownHandle) { Control control = Control.FromHandle(windownHandle); Bitmap image = new Bitmap(control.Width, control.Height); Graphics gp = Graphics.FromImage(image); IntPtr dc = gp.GetHdc(); PrintWindow(windownHandle, dc, 0); gp.ReleaseHdc(); gp.Dispose(); return image; } [DllImport("user32.dll")] private static extern bool PrintWindow( IntPtr hwnd, // Window to copy,Handle to the window that will be copied. IntPtr hdcBlt, // HDC to print into,Handle to the device context. UInt32 nFlags // Optional flags,Specifies the drawing options. It can be one of the following values. ); } }
![]() |
Austin Liu 刘恒辉
Project Manager and Software Designer E-Mail:lzhdim@163.com Blog:https://lzhdim.cnblogs.com 欢迎收藏和转载此博客中的博文,但是请注明出处,给笔者一个与大家交流的空间。谢谢大家。 |




浙公网安备 33010602011771号