The projects are intended to be used on a desktop environment, not on a web page (project on the first link is completely wrong!).
You get a black screen because you capture the screen where the application is running, so you get the screen of the server, and if there is no user logged in, the screen is black!
You can't use this code to capture remote web client screen.
try to use the WebBrowser control instead and render the result on a bitmap:
<asp:TextBox ID="txtUrl" runat="server" Text = "" />
<asp:Button Text="Capture" runat="server" OnClick="Capture" />
<br />
<asp:Image ID="imgScreenShot" runat="server" Height="300" Width="400" Visible = "false" />
code-behind:
using System.IO;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
protected void Capture(object sender, EventArgs e)
{
string url = txtUrl.Text.Trim();
Thread thread = new Thread(delegate()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
browser.Navigate(url);
browser.Width = 1024;
browser.Height = 768;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser browser = sender as WebBrowser;
using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height))
{
browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] bytes = stream.ToArray();
imgScreenShot.Visible = true;
imgScreenShot.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
}
}
}