첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System.Drawing;
using System.Windows.Forms;

#region 캡처하기 - Capture(url, width, height)

/// <summary>
/// 캡처하기
/// </summary>
/// <param name="url">URL</param>
/// <param name="width">너비</param>
/// <param name="height">높이</param>
/// <returns>Bitmap 객체</returns>
public Bitmap Capture(string url, int width, int height)
{
    WebBrowser webBrowser = new WebBrowser();

    webBrowser.ScrollBarsEnabled      = false;
    webBrowser.ScriptErrorsSuppressed = true;

    webBrowser.Navigate(strURL);

    while(webBrowser.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }

    webBrowser.Width  = width;
    webBrowser.Height = height;

    if(width == -1)
    {
        webBrowser.Width = webBrowser.Document.Body.ScrollRectangle.Width;
    }

    if(height == -1)
    {
        webBrowser.Height = webBrowser.Document.Body.ScrollRectangle.Height;
    }

    Bitmap bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);

    webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser.Width, webBrowser.Height));

    webBrowser.Dispose();

    return bitmap;
}

#endregion

#region 캡처하기 - Capture(url)

/// <summary>
/// 캡처하기
/// </summary>
/// <param name="url">URL</param>
/// <returns>Bitmap</returns>
public Bitmap Capture(string url)
{
    return Capture(url, -1, -1);
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요