• <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
      • 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.resample Function
        • Image.createQRCode Function
        • Image.takePhoto Function
        • Image.captureSignature Function
        • Image.view Function
        • Image.clear Function
      • List Object
      • Map Object
      • Path
      • Pff 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
    • 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.resample Function

Format
b = image_name.resample(width, height);

b = image_name.
resample(ʃwidth := width,ʅ
                       
ʃheight := heightʅ);

b = image_name.
resample(ʃmaxWidth := max_width,ʅ
                       
ʃmaxHeight := max_heightʅ);
Description
The Image.resample function resamples the image held by the Image object. Resampling modifies the dimensions of the image by either downsampling or upsampling the image. A loss of image quality may occur during the resampling process.
In the first version of the function, two numeric expressions, width and height, specify the new dimensions, in pixels, of the image. If one of the arguments is notappl, then the other dimension will be calculated by maintaining the original image's aspect ratio (the ratio of the width to the height). For example, if an image is 800 x 600, each of the following function calls results in a 400 x 300 image:
image_name.resample(400, 300);
image_name.
resample(400, notappl);
image_name.
resample(notappl, 300);
The second and third versions of the function, accessed by using named arguments, provide additional ways to control how the image is resampled. Specifying both width and height is equivalent to the first version of the function; specifying only one of the arguments is as if notappl were specified for the other argument. Providing a max_width and/or max_height will conditionally resample an image only if the image's width or height exceeds the provided maximum. Using the 800 x 600 example from above:
image_name.resample(maxWidth := 400);
image_name.
resample(maxHeight := 1200);
The first function call results in a resampling to 400 x 300. The second function call does not result in a resampling because the original height, 600, does not exceed 1200. In this case, the function still returns 1 even though the image was not resampled.
Return Value
The function returns a logical value of 1 (true) if the image was resampled, 0 (false) if there was an error, and default if the image object does not contain an image.
Example 1
// create thumbnails for every image in the Photos directory,
// placing the thumbnails in the Thumbnails directory
List string image_listing;
dirlist(image_listing, "Photos", "*.jpg;*.png");

do numeric counter = 1 while counter <= image_listing.length()

   
Image thumbnail_image;

   
if thumbnail_image.load(image_listing(counter)) then

       
// create a thumbnail at 25% of the original image size
        thumbnail_image.resample(thumbnail_image.width() / 4, thumbnail_image.height() / 4);

       
// prefix the thumbnail filename with the text "tn"
        string thumbnail_filename = Path.concat("Thumbnails", "tn" + Path.getFileName(image_listing(counter)));

        thumbnail_image.
save(thumbnail_filename);

   
endif;

enddo;
Example 2
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.width Function, Image.height Function