0

i have local file that contain some html with javascript and i want to capture it and save it as an image.

i tried to do it with WebBrowser:

            WebBrowser browser = new WebBrowser();
            browser.Navigate("C:\\charts\\pie.html");
            HtmlDocument doc = browser.Document;
            Bitmap bitmap = GenerateScreenshot(browser);
            bitmap.Save("c:\\charts\\sample.png");


        public static Bitmap GenerateScreenshot(WebBrowser wb)
        {
            wb.ScrollBarsEnabled = false;
            wb.ScriptErrorsSuppressed = true;

            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();

            return bitmap;
        }

but i get every time blank image...

any idea??

1 Answers1

0

DrawToBitmap has limitations and dont always work as expected. Try instead work with native GDI+

As Cory already answered here

Refer another example here

Community
  • 1
  • 1
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115