Sunday, April 12, 2009

Create a screenshot image of a web page

I use HtmlCapture to capture a screenshot of a web page:

Imports HtmlCapture

Module Module1

Sub Main()

CreatePreviewImage()

End Sub

Private Sub CreatePreviewImage()

Dim theURL As String = "http://www.google.com.au/"

Dim snap As New SnapShooter

Dim snapResult As HtmlCaptureResult

snap.SetRegInfo("username", "licencekey")

snap.SetDelayTime(6000)

snap.SetTimeOut(15000)

snap.SetMinBrowserSize(SnapDimensions.BrowserWidth, SnapDimensions.BrowserHeight)

snap.SetClipRect(0, 0, SnapDimensions.ClipWidth, SnapDimensions.ClipHeight)

snap.SetThumbSize(SnapDimensions.ThumbWidth, SnapDimensions.ThumbHeight, True)

snap.SetJpegQuality(CByte(SnapDimensions.JpegQuality))

snapResult = snap.SnapUrl(theURL)

If snapResult = HtmlCaptureResult.HCR_SUCCESS Then

' success, save the image as a JPEG

snap.SaveImage("screenshot.jpg")

Else

' timeout, so throw error

Dim ex As New Exception("Timeout on capturing.")

Throw ex

End If

End Sub

Public Enum SnapDimensions As Integer

ThumbWidth = 200

ThumbHeight = 150

BrowserWidth = 1024

BrowserHeight = 768

ClipWidth = 1024

ClipHeight = 768

JpegQuality = 70

End Enum

End Module


Reference:

HtmlCapture Support

blog comments powered by Disqus