CapturePreview - cWebView2Browser
Captures the currently displayed document into an image
Type: Procedure
Parameters
| Parameter | Type | Description |
|---|---|---|
| eImageFormat | OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT | Image format to be used:OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG or OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_JPEG |
Syntax
Procedure CapturePreview OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT eImageFormat
Call Example
Send CapturePreview eImageFormat
Description
Captures the currently displayed document into an image.
This method works asynchronously and will return immediately.
The OnCapturePreviewCompleted event should be implemented to process the generated image.
Sample
The sample below shows how to store the image to disk.
Object oWebView2BrowserCtrl is a cWebView2Browser
Set Size to 87 250
Set Location to 0 0
Set psLocationURL to "https://www.dataaccess.com"
Set peAnchors to anAll
// Fires after CapturePreview is called with the image data, we show a dialog and save it do disk.
Procedure OnCapturePreviewCompleted OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT eImageFormat UChar[] ByRef ucImageData
Boolean bOk
String sPath
Integer iChnl
Set File_Title of oSaveAsDialog to "Screenshot"
If (eImageFormat = OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG) ;
Set Filter_Index of oSaveAsDialog to 1
Else ;
Set Filter_Index of oSaveAsDialog to 2
Get Show_Dialog of oSaveAsDialog to bOk
If (bOk) Begin
Get File_Name of oSaveAsDialog to sPath
Move (Seq_New_Channel()) to iChnl
Direct_Output channel iChnl ("binary:" + sPath)
Write channel iChnl ucImageData
Close_Output channel iChnl
Send Seq_Release_Channel iChnl
Runprogram Shell Background sPath
End
End_Procedure
End_Object
Object oSaveAsDialog is a SaveAsDialog
Set Filter_String to "Image PNG (.png)|*.png|Image JPEG (.jpg)|*.jpg"
End_Object
Object oSaveAsPngBtn is a Button
Set Size to 14 68
Set Location to 93 76
Set Label to 'Save screen as PNG'
Set peAnchors to anBottomLeft
// fires when the button is clicked
Procedure OnClick
Send CapturePreview of oWebView2BrowserCtrl OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG
End_Procedure
End_Object
Object oSaveAsPngBtn is a Button
Set Size to 14 68
Set Location to 93 5
Set Label to 'Save screen as JPG'
Set peAnchors to anBottomLeft
// fires when the button is clicked
Procedure OnClick
Send CapturePreview of oWebView2BrowserCtrl OLECOREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_JPEG
End_Procedure
End_Object