C#

웹브라우저 HtmlElement 캡처하기 c# capture webbrowser html element

public Bitmap captureHtmlElement(WebBrowser wb, HtmlElement elm)
{
    Bitmap bit;
    Bitmap rtn;
    Rectangle rect;
    Size wb_all_size;
    Size wb_origin_size;
    Graphics g;
    
    wb_all_size = new Size(wb.Document.Body.ScrollRectangle.Width, wb.Document.Body.ScrollRectangle.Height);
    wb_origin_size = new Size(wb.Size.Width, wb.Size.Height);
    rect = getRect(elm);
    wb.Size = wb_all_size;
    bit = new Bitmap(wb.Width, wb.Height);
    rtn = new Bitmap(rect.Width, rect.Height);
    g = Graphics.FromImage(rtn);

    //웹브 전체 캡처하고
    wb.DrawToBitmap(bit, new Rectangle(0, 0, wb.Width, wb.Height));
    //일부분 다시 잘라내기
    g.DrawImage(bit, 0, 0, rect, GraphicsUnit.Pixel);

    //웹브 크기 원래대로
    wb.Size = wb_origin_size;
    return rtn;
}

public Rectangle getRect(HtmlElement elm)
{
    Rectangle r = elm.OffsetRectangle;
    Rectangle pr;

    HtmlElement parent = elm.OffsetParent;
    while (parent != null)
    {
        pr = parent.OffsetRectangle;
        r.X += pr.X;
        r.Y += pr.Y;
        parent = parent.OffsetParent;
    }

    return r;
}


별건아니고

html element 가져오고싶을때..

웹브라우저가 visible이 false여도 된다. DC가 메모리를 가리키고잇을테니 상관없지



this function is to capture html element from web browser control.

if your web browser control doesn't support function "DrawToBitmap" then you can find some function performing like it (google it)


wwwwwwwwwwwwwwwwwwwwwwww

ching chang chong wwwwwwwwwwwwwwwwwwwwww

,

알림

이 블로그는 구글에서 제공한 크롬에 최적화 되어있고, 네이버에서 제공한 나눔글꼴이 적용되어 있습니다.

카운터

Today :
Yesterday :
Total :

태그