• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Numeric Values
      • String Values
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
        • Image Statement
        • Image.load Function
        • Image.save Function
        • Image.width Function
        • Image.height Function
        • Image.getExif Function
        • EXIF Tags
        • Image.resample Function
        • Image.createQRCode Function
        • Image.takePhoto Function
        • Image.captureSignature Function
        • Image.view Function
        • Image.clear Function
        • JSON Representation
      • List Object
      • Map Object
      • Path
      • Pff Object
      • StringWriter Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Image.save Function

Format
b = image_name.save(image_file_pathʃ, quality := qualityʅ);
Description
The Image.save function writes the contents of the Image object to a file specified by the string expression image_file_path. The image can be saved in the following formats, with the format determined by the file extension:
  • JPEG (.jpg/.jpeg).
  • PNG (.png).
  • WebP (.webp).
  • BMP (.bmp).
  • ICO (.ico).
Although GIF (.gif) files can be loaded, images cannot be saved to this format.
When saving to JPEG or lossy WebP formats, the quality can be specified using a named argument. The numeric expression quality must be a value from 0 to 100, with 100 being the best quality. If not specified, a value of 95 is used. The file size will be bigger the higher the quality number. WebP files can contain lossy or lossless image data. To save as a lossless WebP, use the value of notappl for quality. This quality value is ignored if not saving to JPEG or WebP formats.
ICO files have a maximum dimension of 256, and the image will be resampled prior to saving if either of the image's dimensions exceed this value.
Return Value
The function returns a logical value of 1 (true) if the image was saved, 0 (false) if there was an error writing the file, and default if the Image object does not contain an image.
Example
Image roof_photo;

if roof_photo.takePhoto("Take a photo of the household's roof.") then

   
// in case the device's camera takes photos with an unnecessarily
    // large resolution, resample the image to a more reasonable size
    roof_photo.resample(maxWidth := 1600, maxHeight := 1200);

   
// save the image using the household key...
    string base_filename = Path.concat(application, "Roof Photos", key(HH_DICT));

   
// ...with 90 quality to prevent the JPEG from being too large
    roof_photo.save(base_filename + ".jpg", quality := 90);

endif;
See also: Image Object, Image.load Function