• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • Case Object
        • Document Object
        • File Object
        • Freq Object
        • Geometry Object
        • HashMap Object
        • Image Object
        • List Object
        • Map Object
        • Pff Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Image Object

In logic, an Image object facilitates the storing and manipulating of images. Image objects can contain photos, signatures, or other kinds of visual media. CSPro supports reading and writing to JPEG, PNG, and BMP image formats.
Functionality
An Image object is a CSPro logic object that can be defined as a binary dictionary item or created as a logic variable. The following functions can be called via dot notation:
FunctionDescription
loadReads an image from a file and stores its contents in the Image object.
saveWrites the contents of the Image object to a file.
widthReturns the width of the image in pixels.
heightReturns the height of the image in pixels.
resampleResamples the image to change the image's dimensions.
createQRCodeCreates a QR code representing a text string.
takePhotoTakes a photo using a device's camera and stores the photo in the Image object. (Android only.)
captureSignatureAllows the drawing of a signature and stores the captured signature in the Image object. (Android only.)
viewDisplays the image held by the object.
clearClears the Image object's contents.
 
getLabelReturns the symbol's label.
getNameReturns the symbol's name.
getJsonReturns the symbol's metadata and value represented in JSON.
getValueJsonReturns the symbol's value represented in JSON.
updateValueFromJsonModifies the symbol based on a JSON representation of the value.
In addition to these object functions, Image objects can be used as arguments to the filename and view functions.
Assignments
Image objects can be assigned to other Image objects, which will replace the Image's contents with the contents from the assigned Image object.
image_name = another_image_name;
It is also possible to assign Image objects to a Document:
document_name = image_name;
You can also make the reverse assignment, assigning a document to an Image object. A runtime error will occur if the Document's data was not a valid image.
image_name = document_name;
When an Image is used as an argument to a user-defined function, it is passed by reference.
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: Document Object