i am trying to create image from webBrowser
control's output. the following is what i have tried. and somewhat achieved what i want, but problem is the image is not of full height, it gets trims after some height.
In the picture you can see there are 4 rows but the image is 2 n half rows. please guide.
HTML 1-4 is in webBrowser
, and after space 1-3 is image created from code below.
here is code:
private void WebBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
{
var wb = (WebBrowser)sender;
var htmlDoc = wb.Document as mshtml.HTMLDocument;
if (htmlDoc == null || htmlDoc.body == null) return;
var body = (mshtml.IHTMLElement2)htmlDoc.body;
wb.Height = body.scrollHeight;
wb.Width = body.scrollWidth;
var imgScreen = new Image
{
Width = body.scrollWidth,
Height = body.scrollHeight,
Source = new DrawingImage(VisualTreeHelper.GetDrawing(wb))
};
// Add Image to the UI
StackPanel1.Children.Add(imgScreen);
}
Also tried the following code same result:
DrawingVisual vis = new DrawingVisual();
DrawingContext cont = vis.RenderOpen();
cont.DrawDrawing(VisualTreeHelper.GetDrawing(wb));
cont.Close();
RenderTargetBitmap rtb = new RenderTargetBitmap(body.scrollWidth, body.scrollHeight, 96d, 96d, PixelFormats.Default);
rtb.Render(vis);
imgScreen1.Source = rtb;