Picture Object

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

The Picture object provides a scripting interface to an image, which you can use in your testing process.

To obtain a Picture object in scripts, you can use one of the following methods and properties:

  • The Picture method of the Utils object - Returns an empty Picture object.
  • The Picture method of the appropriate onscreen object - Returns the Picture object that corresponds to a window, window regions or any other onscreen object (the window object inherits all methods and properties of the onscreen object).
  • The PagePicture method of the Page object - Returns the Picture object that corresponds to a rectangular area of the appropriate web page. You can use this method to capture images that include page regions, which are beyond the page’s visible area and that are accessible via scroll bars.
  • Regions.GetPicture returns the Picture object that corresponds to an image stored in the Regions collection of the Stores project item.
  • Sys.Clipboard - Returns the Picture object that corresponds to the image held in the clipboard (if any). The image must be captured using Windows shortcuts (Alt+PrtScn or PrtScn) or copied to the clipboard via TestComplete or an external image editor.
  • The Picture method of the Device.Desktop object - Returns the Picture object that corresponds to the specified rectangular area of the mobile device's screen.

Members

Example

The following example demonstrates how to create an empty Picture object using the Utils.Picture method and how to work with images using methods of the Picture object.

JavaScript

function Test1()
{
  var Pict, NewPict, x, y;

  // Creates a new empty Picture object
  Pict = Utils.Picture;

  // Loads the image from a file and posts it to the log
  Pict.LoadFromFile("D:\\Data\\my_image.png");
  Log.Picture(Pict);

  // Obtains the bounds of the new image
  x = Pict.Size.Width - 10;
  y = Pict.Size.Height - 10;

  // Obtains the new Picture object containing the specified rectangular area of the loaded image
  NewPict = Pict.GetRect(0, 0, x, y);

  // Changes the color of the top left pixel of the new image to the red color
  NewPict.$set("Pixels", 0, 0, clRed);

  // Saves the obtained picture to the new file and posts the image to the log
  NewPict.SaveToFile("D:\\Data\\my_new_image.png");
  Log.Picture(NewPict);
}

JScript

function Test1()
{
  var Pict, NewPict, x, y;

  // Creates a new empty Picture object
  Pict = Utils.Picture;

  // Loads the image from a file and posts it to the log
  Pict.LoadFromFile("D:\\Data\\my_image.png");
  Log.Picture(Pict);

  // Obtains the bounds of the new image
  x = Pict.Size.Width - 10;
  y = Pict.Size.Height - 10;

  // Obtains the new Picture object containing the specified rectangular area of the loaded image
  NewPict = Pict.GetRect(0, 0, x, y);

  // Changes the color of the top left pixel of the new image to the red color
  NewPict.Pixels(0,0)= clRed;

  // Saves the obtained picture to the new file and posts the image to the log
  NewPict.SaveToFile("D:\\Data\\my_new_image.png");
  Log.Picture(NewPict);
}

Python

def Test1():
  
  # Creates a new empty Picture object
  Pict = Utils.Picture;

  # Loads the image from a file and posts it to the log
  Pict.LoadFromFile("D:\\Data\\my_image.png")
  Log.Picture(Pict)

  # Obtains the bounds of the new image
  x = Pict.Size.Width - 10
  y = Pict.Size.Height - 10

  # Obtains the new Picture object containing the specified rectangular area of the loaded image
  NewPict = Pict.GetRect(0, 0, x, y)

  # Changes the color of the top left pixel of the new image to the red color
  NewPict.Pixels[0,0] = clRed

  # Saves the obtained picture to the new file and posts the image to the log
  NewPict.SaveToFile("D:\\Data\\my_new_image.png")
  Log.Picture(NewPict)

VBScript

Sub Test1
  Dim Pict, NewPict, x, y

  ' Creates a new empty Picture object
  Set Pict = Utils.Picture

  ' Loads the image from a file and posts it to the log
  Call Pict.LoadFromFile("D:\Data\my_image.png")
  Log.Picture(Pict)

  ' Obtains the bounds of the new image
  x = Pict.Size.Width - 10
  y = Pict.Size.Height - 10

  ' Obtains the new Picture object containing the specified rectangular area of the loaded image
  Set NewPict = Pict.GetRect(0, 0, x, y)

  ' Changes the color of the top left pixel of the new image to the red color
  NewPict.Pixels(0,0)= clRed

  ' Saves the obtained picture to the new file and posts the image to the log
  Call NewPict.SaveToFile("D:\Data\my_new_image.png")
  Log.Picture(NewPict)
End Sub

DelphiScript

procedure Test1;
var Pict, NewPict, x, y;
begin
  // Creates a new empty Picture object
  Pict := Utils.Picture;

  // Loads the image from a file and posts it to the log
  Pict.LoadFromFile('D:\Data\my_image.png');
  Log.Picture(Pict);

  // Obtains the bounds of the new image
  x := Pict.Size.Width - 10;
  y := Pict.Size.Height - 10;

  // Obtains the new Picture object containing the specified rectangular area of the loaded image
  NewPict := Pict.GetRect(0, 0, x, y);

  // Changes the color of the top left pixel of the new image to the red color
  NewPict.Pixels(0,0) := clRed;

  // Saves the obtained picture to the new file and posts the image to the log
  NewPict.SaveToFile('D:\Data\my_new_image.png');
  Log.Picture(NewPict);
end;

C++Script, C#Script

function Test1()
{
  var Pict, NewPict, x, y;

  // Creates a new empty Picture object
  Pict = Utils["Picture"];

  // Loads the image from a file and posts it to the log
  Pict["LoadFromFile"]("D:\\Data\\my_image.png");
  Log["Picture"](Pict);

  // Obtains the bounds of the new image
  x = Pict["Size"]["Width"] - 10;
  y = Pict["Size"]["Height"] - 10;

  // Obtains the new Picture object containing the specified rectangular area of the loaded image
  NewPict = Pict["GetRect"](0, 0, x, y);

  // Changes the color of the top left pixel of the new image to the red color
  NewPict["Pixels"](0,0)= clRed;

  // Saves the obtained picture to the new file and posts the image to the log
  NewPict["SaveToFile"]("D:\\Data\\my_new_image.png");
  Log["Picture"](NewPict);
}

See Also

Picture Property
Picture Method
PagePicture Method (Page Objects)
GetPicture Method
Clipboard Property

Highlight search results