HtmlScreenCapture – Live Writer SDK 中好用的 class
三月 8, 2009
HtmlScreenCapture
可以將 HTML 內容(或指定網址)快照成圖檔。(Provides the ability to capture HTML content into a bitmap. [#])
- 要參考 C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll
程式碼:
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
class Program
{
static void Main(string[] args)
{
// 從指定網址截圖
WindowsLive.Writer.Api.HtmlScreenCapture capture =
new HtmlScreenCapture(new Uri("http://tw.yahoo.com"), 1024/*寬度*/);
System.Drawing.Bitmap bmp = capture.CaptureHtml(5000/*timeoutMs*/);
bmp.Save(@"C:\1.png", System.Drawing.Imaging.ImageFormat.Png);
// 從 html 內容截圖
WindowsLive.Writer.Api.HtmlScreenCapture capture2 = new HtmlScreenCapture(
"<h1>中文測試</h1><p>一些<b>文字</b>"+
"和一個<a href='http://klcin.tw/net'>連結</a></p>", 200);
System.Drawing.Bitmap bmp2 = capture2.CaptureHtml(5000);
bmp2.Save(@"C:\2.png", System.Drawing.Imaging.ImageFormat.Png);
} // Main
} // class
輸出結果:

