1

私は自分の仕事についていくつかのアイデアを得たいと思っています。HTML テーブル コンテンツ コードを画像形式に変更したいと考えています。私は何か考えました。誰でも私にアイデアを教えてください..

4

1 に答える 1

3

出典:ダリン・ディミトロフの回答

最初に、HTML を処理できるレンダリング エンジンと、必要に応じて javascript と css (それらをサポートする場合) が必要です。WebBrowserコントロールを使用することもできますが、もっと良い方法があるかもしれません。

他にもいくつかのオプションがあります。次のリンクを参照してください:
C# を使用した Html テーブル (テキスト) から画像
へ asp.net で HTML のブロックを画像 (例: jpg) に
変換する方法 HTML コントロール (Div またはテーブル) を画像に変換するC# を使用し
て HTML をレンダリング (ビットマップに変換)

コードスニペット:

public Bitmap GenerateScreenshot(string url)
{
    // This method gets a screenshot of the webpage
    // rendered at its full size (height and width)
    return GenerateScreenshot(url, -1, -1);
}

public Bitmap GenerateScreenshot(string url, int width, int height)
{
    // Load the webpage into a WebBrowser control
    WebBrowser wb = new WebBrowser();
    wb.ScrollBarsEnabled = false;
    wb.ScriptErrorsSuppressed = true;
    wb.Navigate(url);
    while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }


    // Set the size of the WebBrowser control
    wb.Width = width;
    wb.Height = height;

    if (width == -1)
    {
        // Take Screenshot of the web pages full width
        wb.Width = wb.Document.Body.ScrollRectangle.Width;
    }

    if (height == -1)
    {
        // Take Screenshot of the web pages full height
        wb.Height = wb.Document.Body.ScrollRectangle.Height;
    }

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
    wb.Dispose();

    return bitmap;
}
于 2012-10-31T06:09:36.587 に答える