Convert html to image at a given size.

Html snapshot can capture the whole html page into image as JPG, TIFF and PNG etc. Sometimes, you may not need a full image but an image at a given width and height. There are several ways to do this:

 1. Use EnableSnapDimensionAsImageSize and SetSnapDimension

     ‘demo how to convert html to image

Dim snap

‘Create the Html Snapshot Object
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)

‘Set the time to wait for web page loading
snap.SetTimeOut CLng(200000)

‘Set the browser window size
snap.SetSnapDimension 250, 250

‘Set this if you want the image size exactly to be 1000,1000
snap.EnableSnapDimensionAsImageSize 1

‘Begin to capture the web page
snap.SnapUrl “http://www.google.com/“, “google.jpg”

‘Free object
Set snap = Nothing

 

2. Use SetClipRect method then you can get out the image with GetBitmapHandle after calling SnapUrl.

3. Get out the whole image with GetBitmapHandle and apply post processing to cut it into any size as you wish