Capture Screen Shots Using ASP.Net Without JavaScript


Description:-

In this article I will explain how to capture a screenshot (snapshot) of a Website web page using ASP.Net using C#.

I have seen many articles using a lot of scripting code to capture the screen shots but the .Net Framework capable of doing this type of thin in a few lines of code. So by considering that requirement in this article especially focusing on beginners and those who want to learn how to capture the screen using ASP.Net and C# without using any scripting language.

We are using the Screen class of Windows Forms to get our requirement that contains the many methods related to screen shots, so we need to add the reference for Windows Forms in our project.

Default.aspx:-
<div>
  <br />
  <h2 style="font-size: x-large; font-weight: bolder;">by Umesh Patel</h2>
  <br />
  <asp:Label ID="Label1" runat="server" Text="Taking ScreenShot"></asp:Label>
  <br />
</div>

Default.aspx.cs:-
protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = "This Screen Shot Taken at " + DateTime.Now.ToString();
    //System.Threading.Thread.Sleep(5000);
    Screnshot();
}

protected void Screnshot()
{
    Capture(@"C:\Users\UmesH\Desktop\ScreenShot.jpg");//path to Save Captured files
}

public static void Capture(string CapturedFilePath)
{
    Bitmap bitmap = new Bitmap
    (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

    Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
    graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size);

    bitmap.Save(CapturedFilePath, ImageFormat.Bmp);
}

Related Posts

Previous
Next Post »

1 comments:

comments

Thanks for comments.....