Picture Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

This method captures an image of visible area of the onscreen object and returns the Picture object that provides scripting interface to the captured image. You can process this object using the Log.Picture method and the image processing methods of the Regions object.

Declaration

TestObj.Picture(ClientX, ClientY, Width, Height, Mouse)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
ClientX [in]    Optional    Integer Default value: 0   
ClientY [in]    Optional    Integer Default value: 0   
Width [in]    Optional    Integer Default value: -1   
Height [in]    Optional    Integer Default value: -1   
Mouse [in]    Optional    Boolean Default value: True   
Result A Picture object

Applies To

All onscreen objects.

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

ClientX

Specifies the left coordinate of the top-left corner of the rectangular area. 0 by default.

ClientY

Specifies the top coordinate of the top-left corder of the rectangular area. 0 by default.

Width

Specifies the width of the rectangular area. The value of -1 (default) indicates that the rectangular area spreads to the right edge of the object.

Height

Specifies the height of the rectangular area. The value of -1 (default) indicates that the rectangular area spreads to the bottom of the object.

Mouse

Specifies whether the captured image will contain the mouse pointer. The default value is True and includes the mouse pointer in the image.

Result Value

The Picture object that represents the captured image.

Remarks

To capture an image of the entire visible area of the onscreen object, call Picture without any parameters.

Note that the method captures only the visible part of the onscreen object. Regions beyond the visible part are not captured. To get the image of such regions, you need to make them visible first (for example, scroll to the desired position) and then call the Picture method.

To get the image of the web page, we suggest using the PagePicture method that automatically scrolls the web page and returns the combined image.

If you have the Aero theme enabled in your system, the screenshots may include a redundant frame around the captured window. To resolve the issue, enable the Disable DWM before capturing image project option. For more information, see Capturing Images In Aero UI Theme.

Desktop testing: If TestObj refers to an object of a non-DPI-aware application running with a DPI setting other than 100%, set the ClientX and ClientY parameter values relative to the application (as if the application is running with the 100% DPI setting).

Web testing: If the Use CSS pixels for scaled pages option is enabled (by default), set the ClientX and ClientY parameter values relative to the web page, regardless of the browser zoom and the system's DPI setting.

Example

The following code captures the entire screen and inserts the captured image into the test log:

JavaScript, JScript

function PictureToLog()
{
  var w = Sys.Desktop.Picture();
  Log.Picture(w, "Screen Image");
}

Python

def PictureToLog():
  w = Sys.Desktop.Picture()
  Log.Picture(w, "Screen Image")

VBScript

Sub PictureToLog
  Set w = Sys.Desktop.Picture
  Log.Picture w, "Screen Image"
End Sub

DelphiScript

procedure PictureToLog;
var w : OleVariant;
begin
  w := Sys.Desktop.Picture;
  Log.Picture(w, 'Screen Image');
end;

C++Script, C#Script

function PictureToLog()
{
  var w = Sys["Desktop"]["Picture"]();
  Log["Picture"](w, "Screen Image");
}

This example demonstrates how to save a captured image to the Regions collection:

JavaScript, JScript

function PictureToRegions()
{
  var w;
  w = Sys.Desktop.ActiveWindow().Picture(10, 10, 60, 60);
  Regions.AddPicture(w, "Image1_bmp");
}

Python

def PictureToRegions():
  w = Sys.Desktop.ActiveWindow().Picture(10, 10, 60, 60)
  Regions.AddPicture(w, "Image1_bmp")

VBScript

Sub PictureToRegions
  Set w = Sys.Desktop.ActiveWindow().Picture(10, 10, 60, 60)
  Regions.AddPicture w, "Image1_bmp"
End Sub

DelphiScript

procedure PictureToRegions;
var
  w : OleVariant;
begin
  w := Sys.Desktop.ActiveWindow().Picture(10, 10, 60, 60);
  Regions.AddPicture(w, 'Image1_bmp');
end;

C++Script, C#Script

function PictureToRegions()
{
  var w;
  w = Sys["Desktop"]["ActiveWindow"]()["Picture"](10, 10, 60, 60);
  Regions["AddPicture"](w, "Image1_bmp");
}

See Also

Picture Object
Regions Object
MouseX Property (Desktop Objects)
MouseY Property (Desktop Objects)
PagePicture Method (Page Objects)

Highlight search results