CaptureBitmap Method

Class

AnyWin.

Action

Saves a bitmap image to a file and returns the absolute or relative path of the captured bitmap.

Syntax

sBitmapDir = window.CaptureBitmap (sBitmapFile[, Rect])
Variable Description
sBitmapDir

The relative or absolute path for the bitmap file location. If you use the default bitmap location when you capture a bitmap (you did not specify a file location), the bitmap is saved in the working directory for the Agent on the machine that runs the Agent. In this case, you do not need to specify the file path, just the filename when you verify the bitmap. If you use a relative path or absolute path when you capture the bitmap, you must specify the full path for the bitmap to verify it. STRING.

Returns the absolute or relative path of the captured bitmap.

sBitmapFile

The name of the file to save the bitmap to. STRING. Append .png to the filename to save the bitmap as a PNG.

Returns the filename.

Rect Optional: The coordinates for the capture region, relative to the window. If you omit Rect, CaptureBitmap captures the entire window. RECT.

Notes

CaptureBitmap captures the contents (and any color table information) of the window as a 32-bit bitmap, without an alpha channel, and saves it in the file sBitmapFile. The bitmap is saved in the working directory of the Silk Test agent on the machine that runs the agent. Silk Test Classic then waits the time interval specified with the OPT_BITMAP_MATCH_INTERVAL option, and then recaptures the window, comparing the result against the first capture to ensure that the image is stable.

You set the number of consecutive bitmaps that must match with the OPT_BITMAP_MATCH_COUNT option. If the image is not stable after the time specified with the OPT_BITMAP_MATCH_TIMEOUT option, Silk Test Classic raises the exception E_BITMAP_NOT_STABLE. You set these options with the SetOption method.

If you use CaptureBitmap with the SYS_CompareBitmap method on the Open Agent, Silk Test Classic automatically switches to the Classic Agent when it runs the SYS_CompareBitmap method. Because multiple calls are performed, you might notice a slight change in performance.

Platform Differences

The bitmap’s format is standard for the system on which you are running Silk Test Classic, and the files are not portable to different platforms. On Windows, the bitmap is a device independent bitmap file. On VMS, the bitmap is a .xpm file.

You specify the coordinates to capture with the argument Rect, which is of the RECT data type. CaptureBitmap interprets the coordinate (0,0) as the top-left corner of the window’s frame. To capture a bitmap of a window’s client area only, specify window.ClientArea as the window to capture, if window is a MoveableWin. For other classes, such as a Control or Menu, just provide the window specifier.

A blinking insertion point can cause the exception E_BITMAP_NOT_STABLE. If this situation occurs, pre-select a range of text to eliminate the insertion point.

Instead of manually capturing baseline bitmaps for your test cases, you can use CaptureBitmap in an automated process to capture baseline bitmaps. When your test case finds an error, you might want to capture a bitmap of the erroneous screen image for subsequent visual analysis or to present to a developer as visual evidence of the error.

Example

[-] testcase capturebitmap_example ()
	[ ] TextEditor.Help.About.Pick () 
	[ ] About.CaptureBitmap ("window.bmp") 
	[ ] SYS_CompareBitmap ("window.bmp","refwin.bmp")
Note: The CaptureBitmap and SYS_CompareBitmap calls can be collapsed into the following VerifyBitmap call:
About.VerifyBitmap ("refwin.bmp")