Date: 02-16-2022
Return to Index
daniel.esquivias, 15 Aug 2007
created by gbSnippets
4.57 (30 votes)
Rate:
vote 1vote 2vote 3vote 4vote 5
Capture an entire web page and save it as an image.
Download WebCapture.zip - 11.6 KB
Download WebCapture1b.zip - 162.5 KB - 08.15.2007
Screenshot - gui2_animated.gif
Update
- 08.15.2007 - user defined image formats, save path, base file name, text overlay/watermark, and screen res guidelines... and some other ideas to implement.
Introduction
I have seen other articles that describe how to accomplish this, but had no luck in getting any to work with Internet Explorer 7. This is a simple example that captures a webpage, inlcuding elements below the fold, and saves it as an image. Here is what to expect:
Screenshot - httpwwwcodeprojectcom.png
Note that this has been resized, captured images are actual size.
Using the code
This example includes only the basics. Images are saved as 's in the same directory as the exe. Saving as a different image format, variable pausing, and given filename should be relatively easy to add.
Collapse | Copy Code
Private Sub GetImage()
If WebBrowser1.Document Is Nothing Then
Return
End If
Try
Dim scrollWidth As Integer
Dim scrollHeight As Integer
scrollHeight = WebBrowser1.Document.Body.ScrollRectangle.Height
scrollWidth = WebBrowser1.Document.Body.ScrollRectangle.Width
WebBrowser1.Size = New Size(scrollWidth, scrollHeight)
Dim bm As New Bitmap(scrollWidth, scrollHeight)
WebBrowser1.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
Dim SaveAsName As String
SaveAsName = Regex.Replace(textWebURL.Text, "(\\|\/|\:|\*|\?|\""|\<|\>|\|)?", "")
bm.Save(SaveAsName & ".png", System.Drawing.Imaging.ImageFormat.Png)
bm.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'
End Try
buttonCapture.Enabled = True
End Sub
'gbs_01432
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm