国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C#實現將網頁保存成圖片的網頁拍照功能

2020-05-23 14:23:12
字體:
來源:轉載
供稿:網友

本文實例主要實現了網頁照相機程序的功能。C#實現將網頁保存成圖片格式,簡單實現網頁拍照,主要是基于ActiveX 組件的網頁快照類,AcitveX 必須實現 IViewObject 接口。因此讀者完全可擴展此類將其用于你的C#軟件項目中。在此特別感謝作者:隨飛提供的代碼。

主要功能代碼如下:

using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;using System.Runtime.InteropServices.ComTypes;using System.Drawing;using System.Windows.Forms;namespace SnapLibrary{  /// <summary>  /// ActiveX 組件快照類,用于網頁拍照,將網頁保存成圖片  /// AcitveX 必須實現 IViewObject 接口  /// 作者:隨飛  /// </summary>  public class Snapshot  {    /// <summary>    /// 取快照    /// </summary>    /// <param name="pUnknown">Com 對象</param>    /// <param name="bmpRect">圖象大小</param>    /// <returns></returns>    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;    }  }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 百色市| 南部县| 临江市| 长汀县| 抚松县| 宜黄县| 乳山市| 宕昌县| 翁牛特旗| 南充市| 青川县| 宁陕县| 渑池县| 武清区| 阳泉市| 祁东县| 阿克苏市| 桂东县| 宜昌市| 莆田市| 北川| 淮北市| 平利县| 江源县| 诸城市| 肥乡县| 二连浩特市| 修武县| 潼关县| 鄂托克旗| 梁山县| 乐至县| 潮州市| 泰宁县| 灵丘县| 昭平县| 蒲城县| 玛沁县| 个旧市| 灵石县| 丰城市|