using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Windows.Forms; using System.Threading; using System.Drawing; namespace WebSiteSnapshotThumbnails { public class WebSiteSnapshot { #region Private Properties private String Url { get; set; } private Int32 BrowserWidth { get; set; } private Int32 BrowserHeight { get; set; } private Bitmap Bitmap { get; set; } #endregion #region Constructors public WebSiteSnapshot(string url, int browserWidth, int browserHeight) { this.Url = url; this.BrowserWidth = browserWidth; this.BrowserHeight = browserHeight; } #endregion #region Public Methods public Bitmap GenerateWebSiteImage() { Thread m_thread = new Thread(new ThreadStart(_GenerateWebSiteImage)); m_thread.SetApartmentState(ApartmentState.STA); m_thread.Start(); m_thread.Join(); return Bitmap; } #endregion #region Private Methods private void _GenerateWebSiteImage() { WebBrowser m_WebBrowser = new WebBrowser(); m_WebBrowser.ScrollBarsEnabled = false; m_WebBrowser.Navigate(Url); m_WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted); while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents(); m_WebBrowser.Dispose(); } private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser m_WebBrowser = (WebBrowser)sender; m_WebBrowser.ClientSize = new Size(this.BrowserWidth, this.BrowserHeight); m_WebBrowser.ScrollBarsEnabled = false; Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height); m_WebBrowser.BringToFront(); m_WebBrowser.DrawToBitmap(Bitmap, m_WebBrowser.Bounds); } #endregion } }
System.Windows
System.Web.UI
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)