웹브라우저 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
'C#' 카테고리의 다른 글
웹브라우저에서 alert 창 hook하기 (1) | 2015.11.17 |
---|---|
ILMerge 오류 Unresolved assembly reference not allowed System.Core (0) | 2015.10.09 |
ILMerge로 dll을 exe에 병합하기 (0) | 2015.10.05 |
현재 외부 IP (Public IP) 가져오는 법 (0) | 2015.09.16 |
UTF8 <-> EUC-KR (URI Encoding) (0) | 2015.08.20 |