ImageConfiguration Object

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

Description

Use ImageConfiguration objects to specify the format of images you save to a file by using the Picture.SaveToFile method.

To create a new ImageConfiguration object, call the Picture.CreatePictureConfiguration method and specify the needed image format as the method parameter. The following image formats are supported:

  • BMP

  • JPEG

  • PNG

  • TIFF

  • GIF

  • ICO

Note: You can use custom images adapters to provide support for additional image formats.

Use the ImageConfiguration object’s properties to specify the color, compression or other settings of the image format. Which properties the object has depends on the image format it specifies:

BMP
  • ColorDepth - Integer. Read/Write. Possible values are —

    Value Description
    0 Native palette
    4 16 colors
    8 256 colors
    16 65536 colors
    32 16777216 colors
    24 True Color
JPEG
  • GrayScale - Boolean. Read/Write. Specifies whether TestComplete will post color or grayscale images.

  • Quality - Integer. Read/Write. Specifies the image compression quality. Possible values are from 1 (the worse quality) to 100 (the best quality).

PNG
  • CompressionLevel - Integer. Read/Write. Specifies the compression level. Possible values are from 0 (no compression, that is, the largest file with the best quality) to 9 (the smallest file size, the best compression with the lowest quality).

  • Interlaced - Boolean. Read/Write. Specifies whether the saved images will be interlaced.

TIFF
  • CompressionType - String. Read/Write. Possible values are —

    • "No compression"
    • "CCITT Group 3"
    • "CCITT Group 4"
    • "LZW compression"

    If you use the CCITT Group 3 or CCITT Group 4 compression, TIFF images will be monochrome.

GIF
  • DitherMode - String. Read/Write. Specifies the dithering mode to be used if the image palette includes more than 256 colors. Possible values are —

    • "Nearest color"
    • "Floyd Steinberg"
    • "Stucki"
    • "Sierra"
    • "Jarvis, Judice & Ninke"
    • "Stevenson & Arche"
    • "Burkes"
  • ColorReduction - String. Read/Write. Specifies the color reduction method to be used for images that include more than 256 colors. Possible values are —

    • "Windows system (20 colors)"
    • "Windows halftone (256 colors)"
    • "Windows grayscale (4 colors)"
    • "Monochrome (black/white)"
    • "Grayscale (256 shades)"
    • "Netscape (216 colors)"
    • "Optimized (8 colors)"
    • "Optimized (16 colors)"
    • "Optimized (32 colors)"
    • "Optimized (64 colors)"
    • "Optimized (128 colors)"
    • "Optimized (256 colors)"
    • "Optimized Windows (256 colors)"
ICO

The object does not have any properties.

To apply the specified format settings, pass the ImageConfiguration object as a parameter to the Picture.SaveToFile method.

Example

The following example demonstrates how you can save an image to a file in the GIF format with the color reduction set to grayscale:

JavaScript, JScript

function SaveImageToGIF()
{
  var source = "C:\\Data\\img.png";
  var target = "C:\\Data\\img_new";

  var pic = Utils.Picture;
  if (pic.LoadFromFile(source))
  {
    // Creates a GIF format configuration
    config = pic.CreatePictureConfiguration("gif");
    config.ColorReduction = "Grayscale (256 shades)";

    // Saves the image in the specified format
    if (! pic.SaveToFile(target, config))
      Log.Warning("Failed to save the image to the specified file");
  }
  else
    Log.Warning("The specified file " + source + " does not exist.");
}

Python

def SaveImageToGIF():
  source = "C:\\Data\\img.png"
  target = "C:\\Data\\img_new"
   
  pic = Utils.Picture()
  if pic.LoadFromFile(source):
    # Creates a GIF format configuration 
    config = pic.CreatePictureConfiguration("gif")
    config.ColorReduction = "Grayscale (256 shades)"

    # Saves the image with the specified format
    if not pic.SaveToFile(target, config):
      Log.Warning("Failed to save the image to the specified file") 
  
  else:
    Log.Warning("The specified file " + source + " does not exist.")

VBScript

Sub SaveImageToGIF

  source = "C:\\Data\\img.png"
  target = "C:\\Data\\img_new"

  Set pic = Utils.Picture
  If pic.LoadFromFile(source) Then
    ' Creates a GIF format configuration
    Set config = pic.CreatePictureConfiguration("gif")
    config.ColorReduction = "Grayscale (256 shades)"

    ' Saves the image in the specified format
    If Not pic.SaveToFile(target, config) Then
      Log.Warning("Failed to save the image to the specified file")
    End If

  Else
    Log.Warning("The specified file " + source + " does not exist.")
  End If

End Sub

DelphiScript

procedure SaveImageToGIF();
  var source, target : string;
  var pic, config : OleVariant;
  begin

  source := 'C:\Data\img.png';
  target := 'C:\Data\img_new';

  pic := Utils.Picture;
  if pic.LoadFromFile(source) then
  begin
    // Creates a GIF format configuration
    config := pic.CreatePictureConfiguration('gif');
    config.ColorReduction := 'Grayscale (256 shades)';

    // Saves the image in the specified format
    if not pic.SaveToFile(target, config) then
      Log.Warning('Failed to save the image to the specified file.');
  end

  else
    Log.Warning('The specified file ' + source + ' does not exist.');
end;

C++Script, C#Script

function SaveImageToGIF()
{
  var source = "C:\\Data\\img.png";
  var target = "C:\\Data\\img_new";

  var pic = Utils["Picture"];
  if (pic["LoadFromFile"](source))
  {
    // Creates a GIF format configuration
    config = pic["CreatePictureConfiguration"]("gif");
    config["ColorReduction"] = "Grayscale (256 shades)";

    // Saves the image in the specified format
    if (! pic["SaveToFile"](target, config))
      Log["Warning"]("Failed to save the image to the specified file");
  }
  else
    Log["Warning"]("The specified file " + source + " does not exist.");
}

The following example demonstrates how you can save an image to a file in the PNG format with the compression level set to 9 (the smallest file size):

JavaScript, JScript

function SaveImageToPNG()
{
  var source = "C:\\Data\\img.png";
  var target = "C:\\Data\\img_new";

  var pic = Utils.Picture;
  if (pic.LoadFromFile(source))
  {
    // Creates a PNG format configuration
    config = pic.CreatePictureConfiguration("png");
    config.CompressionLevel = 9;

    // Saves the image in the specified format
    if (! pic.SaveToFile(target, config))
      Log.Warning("Failed to save the image to the specified file");
  }
  else
    Log.Warning("The specified file " + source + " does not exist.");
}

Python

def SaveImageToPNG():
  source = "C:\\Data\\img.png"
  target = "C:\\Data\\img_new"
   
  pic = Utils.Picture()
  if pic.LoadFromFile(source):
    # Creates a GIF format configuration 
    config = pic.CreatePictureConfiguration("png")
    config.CompressionLevel = 9;
  
    # Saves the image with the specified format
    if not pic.SaveToFile(target, config):
      Log.Warning("Failed to save the image to the specified file") 
  
  else:
    Log.Warning("The specified file " + source + " does not exist.")

VBScript

Sub SaveImageToPNG

  source = "C:\\Data\\img.png"
  target = "C:\\Data\\img_new"

  Set pic = Utils.Picture
  If pic.LoadFromFile(source) Then
    ' Creates a PNG format configuration
    Set config = pic.CreatePictureConfiguration("png")
    config.CompressionLevel = 9

    ' Saves the image in the specified format
    If Not pic.SaveToFile(target, config) Then
      Log.Warning("Failed to save the image to the specified file")
    End If

  Else
    Log.Warning("The specified file " + source + " does not exist.")
  End If

End Sub

DelphiScript

procedure SaveImageToPNG();
  var source, target : string;
  var pic, config : OleVariant;
  begin

  source := 'C:\Data\img.png';
  target := 'C:\Data\img_new';

  pic := Utils.Picture;
  if pic.LoadFromFile(source) then
  begin
    // Creates a PNG format configuration
    config := pic.CreatePictureConfiguration('png');
    config.CompressionLevel := 9;

    // Saves the image in the specified format
    if not pic.SaveToFile(target, config) then
      Log.Warning('Failed to save the image to the specified file.');
  end

  else
    Log.Warning('The specified file ' + source + ' does not exist.');
end;

C++Script, C#Script

function SaveImageToPNG()
{
  var source = "C:\\Data\\img.png";
  var target = "C:\\Data\\img_new";

  var pic = Utils["Picture"];
  if (pic["LoadFromFile"](source))
  {
    // Creates a PNG format configuration
    config = pic["CreatePictureConfiguration"]("png");
    config["CompressionLevel"] = 9;

    // Saves the image in the specified format
    if (! pic["SaveToFile"](target, config))
      Log["Warning"]("Failed to save the image to the specified file");
  }
  else
    Log["Warning"]("The specified file " + source + " does not exist.");
}

See Also

Specifying Log Images Format
CreatePictureConfiguration Method
Image Settings Dialog
Image Adapters

Highlight search results