|
楼主 |
发表于 2013-8-26 17:26:52
|
显示全部楼层
我在网上找了一些代码,可以获得页面里的整个图片,但是我想获得包括地址栏在内的整个浏览器显示的内容,分屏把这一url中的内容截取下来。
如下图所示,进行多屏拷贝。
原先 别人程序中采用using (Bitmap bmp = snap.TakeSnapshot(this.webBrowser.ActiveXInstance, new Rectangle(0, 0, width, height)))
我换成 using (Bitmap bmp = snap.TakeSnapshot(IE, new Rectangle(0, 0, width, height)))
总是报错- public Bitmap TakeSnapshot(object pUnknown, Rectangle bmpRect)
- {
- if (pUnknown == null)
- return null;
- //必须为com对象
- if (!Marshal.IsComObject(pUnknown))
- return null;
- //IViewObject 接口
- SnapLibrary.UnsafeNativeMethods.IViewObject ViewObject = null;
- IntPtr pViewObject = IntPtr.Zero;
- //内存图
- Bitmap pPicture = new Bitmap(bmpRect.Width, bmpRect.Height);
- Graphics hDrawDC = Graphics.FromImage(pPicture);
- //获取接口
- object hret = Marshal.QueryInterface(Marshal.GetIUnknownForObject(pUnknown),
- ref UnsafeNativeMethods.IID_IViewObject, out pViewObject);
- try
- {
- ViewObject = Marshal.GetTypedObjectForIUnknown(pViewObject, typeof(SnapLibrary.UnsafeNativeMethods.IViewObject)) as SnapLibrary.UnsafeNativeMethods.IViewObject;
- //调用Draw方法
- ViewObject.Draw((int)DVASPECT.DVASPECT_CONTENT,
- -1,
- IntPtr.Zero,
- null,
- IntPtr.Zero,
- hDrawDC.GetHdc(),
- new NativeMethods.COMRECT(bmpRect),
- null,
- IntPtr.Zero,
- 0);
- Marshal.Release(pViewObject);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- throw ex;
- }
- //释放
- hDrawDC.Dispose();
- return pPicture;
- }
复制代码 |
|