In this tutorial you will learn how to capture webpage screenshot in asp.net using c#. You may got a requirement to capture the screenshot when user submits the form , etc. Most of the people purchase third party dll files and use them in their project to capture the screenshot of webpage. It is quite easy in asp.net and there is no need to purchase any dll. Let's have a look over how to do so.
How to capture web page screenshot in asp.net using c#
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Collections.Generic;using System.Web.Services;using System.Text;using System.Windows.Forms;//must be included for capturing screenshotpublic partial class capture_webpage_screenshot : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void btnSave_Click(object sender, EventArgs e){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(@"c:\screenshot\myscreenshot.bmp", ImageFormat.Bmp);}}
The code is ready. Just you have to do the following steps.
- Right click the project name
- Add reference -> .net tab and then choose system.windows.forms namespace then press ok button.
- In .aspx code behind file you have to import the System.Windows.Formsnamespace and that’s it.
2 comments:
This is not working!
How can I see my page on the server there is a page?
The handle is invalid
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The handle is invalid
Source Error:
Line 8424: Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(s_Bitmap)
Line 8425:
Line 8426: g.CopyFromScreen(25, 25, 25, 25, s_Bitmap.Size)
Line 8427:
Line 8428:
try this link:
http://easy-asp-net.blogspot.in/2014/04/how-to-save-image-using-image-url.html
Post a Comment