Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Stats
Snapshot using WebBrowser
class Program
{
    [STAThread]
    public static void Main(string[] args)
    {
        var image = Capture("http://www.yahoo.com", 1024, 768);
        image.Save("aa.png", System.Drawing.Imaging.ImageFormat.Png);
    }

     
    static Image Capture(string url, int width, int height)
    {
        using (WebBrowser wb = new WebBrowser())
        {
            // skip script error
            wb.ScriptErrorsSuppressed = true;
            wb.ScrollBarsEnabled = false;
            wb.AllowNavigation = true;
            // Set the size of the WebBrowser control
            wb.Width = width;
            wb.Height = height;
            ServicePointManager.ServerCertificateValidationCallback
                = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) =>
                {
                    return true;
                });


            if (width == -1)
            {
                // Take Screenshot of the web pages full width
                wb.Width = wb.Document.Body.ScrollRectangle.Width;
            }

            if (height == -1)
            {
                // Take Screenshot of the web pages full height
                wb.Height = wb.Document.Body.ScrollRectangle.Height;
            }

            wb.Navigate(url);
            while (wb.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            System.Threading.Thread.Sleep(5000);
            wb.Update();

            // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
            Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
            wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
            return bitmap;
        }
    }
}