Taking Screenshot of Web Page (with Silverlight Controls) Programatically

自闭症网瘾萝莉.ら 提交于 2019-12-04 13:51:51

I use this code to take schreenshot of web page:

    string myPicsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\SchreenshotFolder\";
    if (System.IO.Directory.Exists(myPicsPath))
    {
      Rectangle bounds = yourBrowser.Bounds;
      using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
      {
        using (Graphics g = Graphics.FromImage(bitmap))
        {
          g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
        }
        bitmap.Save(myPicsPath + System.IO.Path.GetRandomFileName() + ".png", System.Drawing.Imaging.ImageFormat.Png);
      }
    }
    else
    {
      System.IO.Directory.CreateDirectory(myPicsPath);
      MessageBox.Show("Screenshot directory created in " + Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\" + " named SchreenshotFolder\nScreenshot is not saved. Hit button again to save it.");
    }

Structure Bounds of web browser control contains everything you need for taking a screenshot. Or you can reduce size of bitmap if you want to use it as thumbnail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!