wpf 线程 自动保存隐藏窗口 效果图
我正在获取仪表曲线,默认是隐藏的,但曲线一直在绘制。每个一段时间自动要保存成效果图。我用句柄获取隐藏窗口代码如下:
IntPtr hscrdc = GetWindowDC(hWnd);
//Control control = Control.FromHandle(hWnd);
Window xx = (Window)System.Windows.Interop.HwndSource.FromHwnd(hWnd).RootVisual;
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, Convert.ToInt32(xx.Width), Convert.ToInt32(xx.Height));
//IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, width, height);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(hWnd, hmemdc, 0);
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);//删除用过的对象
DeleteDC(hmemdc);//删除用过的对象
return bmp;
以上是图片保存代码
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, Convert.ToInt32(xx.Width), Convert.ToInt32(xx.Height));
运行这个的时候提示hscrdc 被占用。
调用线程无法访问此对象,因为另一个线程拥有该对象。
求助。如何更好截取保存图片
就剩下这么多分,全用上。多谢