How to Save Webpage as Image in C-Sharp ?
This article demonstrates how to save the website page as an image (JPEG, GIF, PNG, BMP or TIFF).
- Step 1: Download the Websites Screenshot .Net Library.
- Step 2: Install it on your computer. You will get the WebsitesScreenshot.dll component in the folder.
- Step 3: Open your visual studio project, add this dll in your project references and try the following sample code.
The following code sample shows you how to save the entire webpage as an image format. You can save the webpage as full size image or your size of thumbnail. Call CaptureWebpage method and pass your webpage url or local HTML file path. After that call SaveImage to save the image in local disk or GetImage method to get the captured image in memory bitmap object.
C# .Net Code.
WebsitesScreenshot.WebsitesScreenshot _Obj; _Obj = new WebsitesScreenshot.WebsitesScreenshot (); WebsitesScreenshot.WebsitesScreenshot.Result _Result; _Result = _Obj.CaptureWebpage("http://www.WebsitesScreenshot.com"); if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured) { _Obj.ImageFormat = WebsitesScreenshot. WebsitesScreenshot.ImageFormats.GIF; _Obj.SaveImage ("c:\\WebsitesScreenshot.gif"); } _Obj.Dispose();
VB .Net code.
Dim _Obj As New WebsitesScreenshot.WebsitesScreenshot Dim _Result As WebsitesScreenshot.WebsitesScreenshot.Result With _Obj _Result = .CaptureWebpage("http://www.WebsitesScreenshot.com") If _Result = WebsitesScreenshot.WebsitesScreenshot. _ Result.Captured Then .ImageFormat = WebsitesScreenshot. _ WebsitesScreenshot.ImageFormats.GIF .SaveImage("c:\WebsitesScreenshot.gif") End If End With _Obj.Dispose()
The following code sample uses the GetImage method to get the captured image in memory and save it to the image format.
C# .Net Code.
WebsitesScreenshot.WebsitesScreenshot _Obj; _Obj = new WebsitesScreenshot.WebsitesScreenshot(); WebsitesScreenshot.WebsitesScreenshot.Result _Result; System.Drawing.Bitmap _MyBitmap = null; _Result = _Obj.CaptureWebpage("www.ConvertHTMLtoImage.com"); if (_Result == WebsitesScreenshot. WebsitesScreenshot.Result.Captured) { //Get captured image in memory _MyBitmap = _Obj.GetImage(); _MyBitmap.Save("c:\\test.png"); _Obj.Dispose(); }
VB .Net code.
Dim _Obj As New WebsitesScreenshot.WebsitesScreenshot Dim _Result As WebsitesScreenshot.WebsitesScreenshot.Result Dim _MyBitmap As System.Drawing.Bitmap With _Obj _Result = .CaptureWebpage("www.ConvertHTMLtoImage.com") If _Result = WebsitesScreenshot. _ WebsitesScreenshot.Result.Captured Then 'Get captured image in memory _MyBitmap = .GetImage _MyBitmap.Save("c:\test.png") _Obj.Dispose() End If End With