Snap functions | |
Functions to take snapshots. | |
| HtmlCaptureResult | SnapUrl (string strUrl) |
| Take a snapshot for the specified URL. | |
| HtmlCaptureResult | SnapHtmlString (string strHtml) |
| Take a snapshot for html text. | |
| HtmlCaptureResult | ReSnap () |
| Repeat the last Snap operation (SnapUrl() or SnapHtmlString()). | |
| HtmlCaptureResult | SnapWebBrowser (IDispatch *pWebBrowser) |
| Take snapshot for an existing web browser. | |
| void | Stop () |
| Cancel the snap job. | |
Image access functions | |
Functions to access the resulting image. | |
| bool | SaveImage (string strFileName) |
| Save the snap's resulting image to a local file after a snap function succeeds. | |
| byte[] | GetImageBytes (string strFormat) |
| Get the in-memory image bytes after a snap function succeeds. | |
| long | GetBmpHandle () |
Get the HBITMAP handle to the resulting image. | |
| long | GetEmfHandle () |
Get the HENHMETAFILE handle to the resulting image. | |
| bool | SaveMultiPageTiff (string strFileName, long nPageHeight) |
| Save the snap's resulting image to multi-page TIFF file after a snap function succeeds. | |
| void | GetImageSize (long *pWidth, long *pHeight) |
| Get the size of resulting image. | |
Snap options | |
Get/set options that affects snap. | |
| long | GetTimeOut () |
| Get the time out value in milliseconds for snap functions. | |
| void | SetTimeOut (long nTimeOut) |
| Set the time out value in milliseconds for snap functions. | |
| long | GetDelayTime () |
| Get the time value in milliseconds to wait for after a html document is downloaded. | |
| void | SetDelayTime (long nDelayTime) |
| Set the time value in milliseconds to wait for after a html document is downloaded. | |
| float | GetZoomRatio () |
| Get the zoom ratio of the html page when taking snapshot. | |
| void | SetZoomRatio (float fZoomRatio) |
| Set the zoom ratio of the html page when taking snapshot. | |
| bool | GetActiveXEnabled () |
| Get if ActiveX is enabled (visible) on a web page. | |
| void | SetActiveXEnabled (bool bEnabled) |
| Set if ActiveX is enabled (visible) on a web page. | |
| bool | GetImageEnabled () |
| Get if images are enabled (visible) on a web page. | |
| void | SetImageEnabled (bool bEnabled) |
| Set if images are enabled (visible) on a web page. | |
| bool | GetJavaEnabled () |
| Get if java applets are enabled on a web page. | |
| void | SetJavaEnabled (bool bEnabled) |
| Set if java applets are enabled on a web page. | |
| bool | GetScriptEnabled () |
| Get if scripts are enabled (can be executed) on a web page. | |
| void | SetScriptEnabled (bool bEnabled) |
| Set if scripts are enabled (can be executed) on a web page. | |
| bool | GetVideoEnabled () |
| Get if videos are enabled (visible) on a web page. | |
| void | SetVideoEnabled (bool bEnabled) |
| Set if videos are enabled (visible) on a web page. | |
| void | GetMinBrowserSize (long *pWidth, long *pHeight) |
| Get the minimum size of the hidden web browser window. | |
| void | SetMinBrowserSize (long nWidth, long nHeight) |
| Set the minimum size of the hidden web browser window. | |
| string | GetStartupScript () |
| Get the JScript code to be executed before each Snap (after document downloaded). | |
| void | SetStartupScript (string strScript) |
| Set the JScript code to be executed before each Snap (after document downloaded). | |
| string | GetCookies () |
| Get the cookies of the webpage just snapped. | |
| void | SetCookies (string strUrl, string strCookies) |
| Set cookie(s) for the specified url. | |
| void | SetPostData (string strPostData) |
| Set post data. | |
| string | GetPostData () |
| Get the post data currently set. | |
Image access options | |
Get/set options that affects image access. | |
| void | GetClipRect (long *pLeft, long *pTop, long *pWidth, long *pHeight) |
| Get the clip rect to the resulting image. | |
| void | SetClipRect (long nLeft, long nTop, long nWidth, long nHeight) |
| Set the clip rect to the resulting image. | |
| void | GetThumbSize (long *pWidth, long *pHeight, bool *pKeepRatio) |
| Get the preset thumbnail image size. | |
| void | SetThumbSize (long nWidth, long nHeight, bool bKeepRatio) |
| Set thumbnail image size. | |
| long | GetBpp () |
| Get color depth of the resulting image. | |
| void | SetBpp (long nBpp) |
| Set color depth of the resulting image. | |
| void | GetDPI (long *pDpiX, long *pDpiY) |
| Get resolution for TIFF, JPEG, PNG and BMP image formats. | |
| void | SetDPI (long nDpiX, long nDpiY) |
| Set resolution for TIFF, JPEG, PNG and BMP image formats. | |
| byte | GetJpegQuality () |
| Get JPEG quality when saving image as JPEG. | |
| void | SetJpegQuality (byte nQuality) |
| Set JPEG quality when saving image as JPEG. | |
| HtmlCaptureTiffEncoder | GetTiffEncoder () |
| Get the TIFF encoder when saving image as TIFF format. | |
| void | SetTiffEncoder (HtmlCaptureTiffEncoder nEncoder) |
| Set the TIFF encoder when saving image as TIFF format. | |
| HtmlCaptureGifEncoder | GetGifEncoder () |
| Get the GIF encoder when saving image as GIF format. | |
| void | SetGifEncoder (HtmlCaptureGifEncoder nEncoder) |
| Set the GIF encoder when saving image as GIF format. | |
| HtmlCaptureDitherMethod | GetDitherMethod () |
| Get the dither method when converting image to B&W. | |
| void | SetDitherMethod (HtmlCaptureDitherMethod nMethod) |
| Set the dither method when converting image to B&W. | |
| long | GetThreshold () |
| Get the threshold value for converting image to B&W. | |
| void | SetThreshold (long nThreshold) |
| Set the threshold value for converting image to B&W. | |
| bool | GetErrorDiffusion () |
| Get if using error diffusion algorithm when decreasing Bpp . | |
| void | SetErrorDiffusion (bool bErrorDiff) |
| Set if using error diffusion algorithm when decreasing Bpp . | |
| bool | GetOptimalPalette () |
| Get if using an optimal palette when decreasing Bpp . | |
| void | SetOptimalPalette (bool bOptimalPal) |
| Set if using an optimal palette when decreasing Bpp . | |
| bool | GetGrayScale () |
| Get if converting resulting image to gray scale in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| void | SetGrayScale (bool bGrayScale) |
| Set if converting resulting image to gray scale in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| bool | GetBlackAndWhite () |
| Get if converting resulting image to B&W in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| void | SetBlackAndWhite (bool bBAndW) |
| Set if converting resulting image to B&W in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| HtmlCaptureInterpolationMode | GetInterpolationMode () |
| Get the interpolation mode when resizing an image. | |
| void | SetInterpolationMode (HtmlCaptureInterpolationMode nMode) |
| Set the interpolation mode when resizing an image. | |
HTML utility functions | |
Some utility functions to retrieve information about the webpage. | |
| string | GetDocumentTitle () |
| Get the title of the web page just snapped. | |
| string | GetDocumentSource () |
| Get the html source of the web page just snapped. | |
| string[] | GetDocumentLinks () |
| Get the URLs of links on the web page just snapped. | |
| string[] | GetDocumentFrames () |
| Get the URLs of frames on the web page just snapped. | |
| string | GetDocumentText () |
| Get the text content of the web page just snapped. | |
| IDispatch * | GetHtmlDocument () |
| Get WebBrowser's html document dispatch interface. | |
Other functions | |
| | |
| string | GetReserved (string strIdx) |
| Get reserved properties. | |
| void | SetReserved (string strIdx, string newVal) |
| Set reserved properties. | |
| void | SetRegInfo (string strUserName, string strRegCode) |
| Set registration info. | |
| HtmlCaptureResult SnapUrl | ( | string | strUrl | ) |
Take a snapshot for the specified URL.
The function navigates a hidden WebBrowser to the specified URL and takes a snapshot for the web page. The resulting image can be saved to file or copied to memory. To take a snapshot for a html string, call SnapHtmlString().
| strUrl | The URL of the web page to be taken snapshot. For example, http://www.polestarsoft.com or file:///C:/test.htm |
Sleep() Win32 API, this function runs a message loop to wait. So windows message can still be processed when SnapUrl() is executing. Call Stop() in a message handler to cancel the execution of SnapUrl() and its return value will be HCR_USER_INTERRUPT.| HtmlCaptureResult SnapHtmlString | ( | string | strHtml | ) |
Take a snapshot for html text.
The function is the same as SnapUrl() except that it takes html text as parameter, not URL. It operates entirely in memory, no temporary files used.
| strHtml | The string contains html text. |
| HtmlCaptureResult ReSnap | ( | ) |
Repeat the last Snap operation (SnapUrl() or SnapHtmlString()).
SnapUrl(LASTURL) or SnapHtmlString(LAST_HTML_STRING).| HtmlCaptureResult SnapWebBrowser | ( | IDispatch * | pWebBrowser | ) |
Take snapshot for an existing web browser.
| pWebBrowser | An IWebBrowser2 interface pointer of the existing web browser. |
| void Stop | ( | ) |
Cancel the snap job.
If SnapUrl(), SnapHtmlString() or ReSnap() is called and blocked, Stop() make them return at once.
| bool SaveImage | ( | string | strFileName | ) |
Save the snap's resulting image to a local file after a snap function succeeds.
| strFileName | The image file name. Since this function uses the extension name to determine image format, it must end with an extension name, for example: "c:\snapshot1.jpg", "d:\snapshot.png", etc. |
true, else false.HBITMAP or an HENHMETAFILE handle, call GetBmpHandle() and GetEmfHandle() respectively. ISnapShooter snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { if(snap.SaveImage("c:\\snapshot.png")) MessageBox("Snapshot saved."); }
| byte [] GetImageBytes | ( | string | strFormat | ) |
Get the in-memory image bytes after a snap function succeeds.
In this way, you can convert html to image in memory.
| strFormat | A string that represents the image format. For example: "PNG", "WMF". For a list of image formats supported, see SaveImage. |
| long GetBmpHandle | ( | ) |
Get the HBITMAP handle to the resulting image.
Call this function after a snap function succeeds. The returned bitmap is also affected by those image access options. If you want them to take effects, set them before call this function.
HBITMAP handle. If the function fails, the return value is NULL. NULL, you need to free the returned bitmap handle with DeleteObject Win32 API.HBITMAP handle (a GDI object). It can be used as a normal GDI object. If you want to get a HENHMETAFILE handle, call GetEmfHandle() instead. ISnapShooter snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { HBITMAP hbmp = (HBITMAP)snap.GetBmpHandle(); if (hbmp != NULL) { pictureBox.SetBitmap(hbmp); //picture box is a CStatic variable //we need not to call DeleteObject(hbmp), since pictureBox will delete it. } }
| long GetEmfHandle | ( | ) |
Get the HENHMETAFILE handle to the resulting image.
Call this function after a snap function succeeds. The returned meta file is also affected by those image access options. If you want them to take effects, set them before call this function.
HENHMETAFILE handle. If the function fails, the return value is NULL. NULL, you need to free the returned meta file with DeleteEnhMetafile Win32 API.HENHMETAFILE handle. Since EMF images are vector images, they can shrink and grow with no distortion. If you want to get a raster image handle, call GetBmpHandle() instead. ISnapShooter snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { HENHMETAFILE hemf = (HENHMETAFILE)snap.GetEmfHandle(); if (hemf != NULL) { CRect rc; GetClientRect(&rc); //get client rect of this window CDC* pDC = GetDC(); //get drawing context PlayEnhMetaFile(pDC->m_hDC, hemf, &rc); //draw it DeleteEnhMetafile(hemf); } }
| bool SaveMultiPageTiff | ( | string | strFileName, | |
| long | nPageHeight | |||
| ) |
Save the snap's resulting image to multi-page TIFF file after a snap function succeeds.
If the resulting image's height is greater than nPageHeight, it will be split into several pages and added to a multi-page TIFF file.
| strFileName | The image file name. | |
| nPageHeight | Max height of a TIFF page. |
true, else false.| void GetImageSize | ( | long * | pWidth, | |
| long * | pHeight | |||
| ) |
Get the size of resulting image.
Call this function after a snap function succeeds.
| pWidth | A pointer to retrieve image width. | |
| pHeight | A pointer to retrieve image height. |
| long GetTimeOut | ( | ) |
Get the time out value in milliseconds for snap functions.
TimeOut property can be used to avoid hang.
TimeOut value in milliseconds. The default TimeOut value is 30000. | void SetTimeOut | ( | long | nTimeOut | ) |
Set the time out value in milliseconds for snap functions.
TimeOut property can be used to avoid hang.
| nTimeOut | TimeOut value in milliseconds. A negative value or zero indicates infinite. |
TimeOut milliseconds from its startup. You can call SetTimeOut() with nTimeOut=-1 to disable TimeOut, then snap functions will not return until it completes or fails. | long GetDelayTime | ( | ) |
Get the time value in milliseconds to wait for after a html document is downloaded.
Sometimes, a web page contains ActiveX or java applet, which takes time to initialize.
| void SetDelayTime | ( | long | nDelayTime | ) |
Set the time value in milliseconds to wait for after a html document is downloaded.
Sometimes, a web page contains ActiveX or java applet, which takes time to initialize.
| nDelayTime | Time value in milliseconds to wait for after a html document is downloaded. Default value is 1000 |
| float GetZoomRatio | ( | ) |
Get the zoom ratio of the html page when taking snapshot.
Default value is 1.0.
| void SetZoomRatio | ( | float | fZoomRatio | ) |
Set the zoom ratio of the html page when taking snapshot.
Default value is 1.0.
| fZoomRatio | A float value indicates the zoom ratio. |
| bool GetActiveXEnabled | ( | ) |
Get if ActiveX is enabled (visible) on a web page.
Default value is TRUE.
| void SetActiveXEnabled | ( | bool | bEnabled | ) |
Set if ActiveX is enabled (visible) on a web page.
Default value is TRUE.
If ActiveXEnabled is set to FALSE, then ActiveX controls on a web page will not be downloaded, which is useful to decrease download time, so as to decrease snap time.
| bool GetImageEnabled | ( | ) |
| void SetImageEnabled | ( | bool | bEnabled | ) |
Set if images are enabled (visible) on a web page.
Default value is TRUE.
If ImageEnabled is set to FALSE, images on a web page will not be downloaded and displayed, which is useful to decrease downloading time, so as to decrease snap time.
| bool GetJavaEnabled | ( | ) |
| void SetJavaEnabled | ( | bool | bEnabled | ) |
Set if java applets are enabled on a web page.
Default value is TRUE.
If JavaEnabled is set to FALSE, java applets on a web page will not be downloaded, which is useful to decrease downloading time, so as to decrease snap time.
| bool GetScriptEnabled | ( | ) |
Get if scripts are enabled (can be executed) on a web page.
Default value is TRUE.
| void SetScriptEnabled | ( | bool | bEnabled | ) |
Set if scripts are enabled (can be executed) on a web page.
Default value is TRUE.
ScriptEnabled is set to FALSE, No scripts on a web page will be executed. This may lead to a disordered image. | bool GetVideoEnabled | ( | ) |
| void SetVideoEnabled | ( | bool | bEnabled | ) |
Set if videos are enabled (visible) on a web page.
Default value is TRUE.
If VideoEnabled is set to FALSE, videos on a web page will not be downloaded and displayed, which is useful to decrease downloading time, so as to decrease snap time.
| void GetMinBrowserSize | ( | long * | pWidth, | |
| long * | pHeight | |||
| ) |
Get the minimum size of the hidden web browser window.
| pWidth | A pointer to retrieve minimum width in pixels. Default value is 800. | |
| pHeight | A pointer to retrieve minimum height in pixels. Default value is 600. |
| void SetMinBrowserSize | ( | long | nWidth, | |
| long | nHeight | |||
| ) |
Set the minimum size of the hidden web browser window.
| nWidth | Minimum width in pixels. Default value is 800. | |
| nHeight | Minimum height in pixels. Default value is 600. |
MAX( MinBrowserSize, WebPageSize ). MinBrowserSize to (0, 0) will make MinBrowserSize take no effects.| string GetStartupScript | ( | ) |
Get the JScript code to be executed before each Snap (after document downloaded).
| void SetStartupScript | ( | string | strScript | ) |
Set the JScript code to be executed before each Snap (after document downloaded).
This function is helpful if you want do some initialization job before snap. The JScript will be executed after the document is fully downloaded.
The following pseudo codes show how to set startup script.
ISnapShooter snap; snap.SetStartupScript("document.linkColor = '#FF0000'"); //the javascript turns the link color to red if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { ... }
| string GetCookies | ( | ) |
Get the cookies of the webpage just snapped.
Call this function after a snap function succeeds.
| void SetCookies | ( | string | strUrl, | |
| string | strCookies | |||
| ) |
Set cookie(s) for the specified url.
Call this function before a snap function to take effects.
| strUrl | The URL of web page whose cookies is to be set. | |
| strCookies | Cookies string to be set in "name1=value1;name2=value2;..." format. |
| void SetPostData | ( | string | strPostData | ) |
Set post data.
| string GetPostData | ( | ) |
| void GetClipRect | ( | long * | pLeft, | |
| long * | pTop, | |||
| long * | pWidth, | |||
| long * | pHeight | |||
| ) |
Get the clip rect to the resulting image.
The default clip rect is (0, 0, 0, 0).
| void SetClipRect | ( | long | nLeft, | |
| long | nTop, | |||
| long | nWidth, | |||
| long | nHeight | |||
| ) |
Set the clip rect to the resulting image.
| nLeft | X-coordinate of the TopLeft point. | |
| nTop | Y-coordinate of the TopLeft point. | |
| nWidth | Width of the clip rect. | |
| nHeight | Height of the clip rect. |
| void GetThumbSize | ( | long * | pWidth, | |
| long * | pHeight, | |||
| bool * | pKeepRatio | |||
| ) |
Get the preset thumbnail image size.
| pWidth | A pointer to retrieve thumbnail image width. | |
| pHeight | A pointer to retrieve thumbnail image height | |
| pKeepRatio | A pointer to retrieve if thumbnail image should keep width/height ratio. |
| void SetThumbSize | ( | long | nWidth, | |
| long | nHeight, | |||
| bool | bKeepRatio | |||
| ) |
Set thumbnail image size.
| nWidth | Width of thumbnail image. | |
| nHeight | Height of thumbnail image. | |
| bKeepRatio | If keeps width/height ratio when getting or saving a thumbnail image. |
ISnapShooter snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { snap.SetThumbSize(300, 300, TRUE); snap.SaveImage("c:\\thumbnail.png"); snap.SetThumbSize(0, 0, FALSE); //disable thumbnail image. snap.SaveImage("c:\\fullsize.png"); }
| long GetBpp | ( | ) |
| void SetBpp | ( | long | nBpp | ) |
Set color depth of the resulting image.
Since this method affects SaveImage(), GetImageBytes() and GetBmpHandle(), call it before them to take effects.
| nBpp | the color depth to be set. Valid Bpp value is 1/4/8/24 |
Bpp is set to 1, the final image will be B&W, this equals to call SetBlackAndWhite(TRUE).Bpp is set to 4, the final image will have 16 colors at most.Bpp is set to 8, the final image will have 256 colors at most.Bpp is set to 24, the final image will be RGB image (i.e. 24bits image). Bpp to values other than 24 will result in reducing color number. For best quality of the resulting image after reducing color, set both OptimalPalette and ErrorDiffusion to TRUE. Set both of them to FALSE for good speed.Bpp to 256+ will have no effects.Bpp to values other than 8 and 24 will have no effects.Bpp to values other than them will have no effects.| void GetDPI | ( | long * | pDpiX, | |
| long * | pDpiY | |||
| ) |
| void SetDPI | ( | long | nDpiX, | |
| long | nDpiY | |||
| ) |
| byte GetJpegQuality | ( | ) |
| void SetJpegQuality | ( | byte | nQuality | ) |
Set JPEG quality when saving image as JPEG.
If the destination image format is JPEG, call this function before SaveImage() and GetImageBytes() to take effects.
| nQuality | JPEG quality from 1 to 100. |
| HtmlCaptureTiffEncoder GetTiffEncoder | ( | ) |
Get the TIFF encoder when saving image as TIFF format.
| void SetTiffEncoder | ( | HtmlCaptureTiffEncoder | nEncoder | ) |
Set the TIFF encoder when saving image as TIFF format.
| nEncoder | A HtmlCaptureTiffEncoder value indicates TIFF encoder. |