Captura de pantalla de la página web (con controles de Silverlight) de forma programática
Tengo una página web que muestra algunos controles de luz plateada. Necesito tomar una captura de pantalla de esta página web mediante programación.
Actualmente usa el control System.Windows.Forms.WebBrowser para tomar capturas de pantalla.
Forms.WebBrowser funciona bien cuando tomo capturas de pantalla para páginas normales. Sin embargo, para las páginas con controles Silverlight no funciona.
Mi código para tomar una captura de pantalla es el siguiente: Mapa de bits mapa de bits = nulo; utilizando (WebBrowser webBrowser = new WebBrowser ()) {webBrowser.ScrollBarsEnabled = false; webBrowser.ScriptErrorsSuppressed = true;
// Set the size of the WebBrowser control
webBrowser.Width = width;
webBrowser.Height = height;
// Load the webpage into a WebBrowser control
webBrowser.Navigate(url);
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
if (width == -1)
{
// Take Screenshot of the web pages full width
webBrowser.Width = webBrowser.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
webBrowser.Height = webBrowser.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser.Width, webBrowser.Height));
}