Saving Images

The VisionPro Display has the ability to save the images that it is displaying, by taking a screen capture of what is being displayed and saving it to a file.

To save an image associated with a VisionPro Display, do the following:

  1. Within a Task, add and configure a Device to acquire or load images, and a VisionPro Tool Block to perform vision tasks on the images.
  2. Create a folder to store the saved images.
    1. In the Designer Project directory (C:\Users\<user_name>\Documents\Cognex Designer\Projects\<Project_Name>), create a folder for the saved images (e.g. "SavedImages").
  3. Add a tag that will be used to associate the path and file name of the saved images.
    1. In the Tag Manager, add a tag (e.g. "PathFileName") with a String Data Type.
  4. Configure the Page with a VisionPro Display, a TextBox to enter a filename for the image, and a Button to initiate the save action.
    1. Add either a VisionPro Display, and set the Subject property to either an image output by a Device or a Tool Block.
    2. Add a TextBox.
    3. Add a Button, and in the Text property enter "Save Image".
    4. Right-click the Button, and from the menu, select the OnClick script point.
    5. In the Script Editor for the OnClick script, add the following code:

      $PathFileName = $System.Info.ProjectPath + "\\SavedImages\\" + $Pages.Page.TextBox.Text;

      $Pages.Page.VisionProDisplay.Save(true, $PathFileName);

      Note: When the fitImage argument is set to True, the unscaled image and graphics will be saved (however, the graphics are clipped at the image boundary). When it is set to False, only the image, as it currently displayed, will be saved.
  5. Enter Test Mode and enter a name for the image and press the Save Image Button. The image file should appear in the specified directory.