AppGetPicture Method (CLIENT)


PLB Web Only, 9.9

 

The AppGetPicture method can be used for taking pictures and for choosing images from the device's image library. The method uses the following format:

 

[label]

{object}.AppGetPicture

[GIVING {return}] [USING [*Options=]{options}]]

 

Where:

label

Optional. A Program Execution Label.

object

Required. A CLIENT object.

return

Optional. A Numeric Variable that returns the success or failure of the method.

options

Optional. A Character String Variable or string literal that specifies a JSON object that is passed directly to the Cordova routine used for this method.

Flags Affected: OVER, ZERO

Note the following:

  1. This method is only used for a Sunbelt PL/B Web Client App using Cordova\PhoneGap operations. See the following link for details on the Cordova plugin used:

  2.  

         https://www.npmjs.com/package/cordova-plugin-camera

     

  3. The ZERO flag is set when the {return} value is zero.

  4. The OVER flag is set if the value returned is too large to be stored into the {return} variable.

  5. The {options} parameter controls the behavior of the Cordova plugin when the AppGetPicture method operation is being performed. The {options} parameter is passed directly as a JSON object to the Cordova routine.

  6.  

    If {options} parameter has { "cleanUp": true }, the AppGetPicture method only removes intermediate image files that are kept in temporary storage on the device.

     

    The JSON object supports and can include the following fields:

     

    Field

    Description

    quality

    Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera's resolution is unavailable.)

    destinationType

    This JSON field chooses the format of the data returned. One of the following numeric values is allowed:

    DATA_URL EQU 0 // Return base64 encoded string

    FILE_URI EQU 1 // Default Return file uri

    NATIVE_URI EQU 2 // Return native uri

    sourceType

    This JSON field sets the source of the picture on the device. One of the following numeric values is allowed:

    PHOTOLIBRARY EQU 0 // Choose image from the picture library

    CAMERA EQU 1 // Default Take picturefrom camera

    SAVEDPHOTOALBUM EQU 2 // Choose image from the picture library

    allowEdit

    This JSON field can allow simple editing of image on the device before selection. The allowed values are true and false. The default is true.

    encodingType

    This JSON field chooses the returned image file's encoding. One of the following numeric values is allowed:

    JPEG EQU 0 // Default Return JPEG encoded image

    PNG EQU 1 // Return PNG encoded image

    targetWidth

    This JSON field specifies the width in pixels to scale the returned image. This field must be used with `targetHeight`. The aspect ratio remains constant.

    targetHeight

    This JSON field specifies the height in pixels to scale the returned image. This field must be used with `targetWidth`. The aspect ratio remains constant.

    mediaType

    This JSON field sets the type of media to select from on the device. This field only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. One of the following numeric values is allowed:

    PICTURE EQU 0 // Default Allow selection of still pictures only.

    VIDEO EQU 1 // Allow selection of video only. only returns URL.

    ALLMEDIA EQU 2 // Allow selection from all media types

    correctOrientation

    This JSON field allows rotation of the image to correct for the orientation of the device during capture.

    saveToPhotoAlbum

    This JSON field causes the image to be saved to the photo album on the device after capture.

    cameraDirection

    This JSON field chooses the camera to use (front- or back-facing). One of the following numeric values is allowed:

    BACK EQU 0 // Default Use the back-facing camera

    FRONT EQU 1 // Use the front-facing camera

     

  7. This method starts an asynchronous operation on the mobile device which returns the result using the 'AppEventGetPict' CLIENT object event where the event data is returned in ARG1 which contains a JSON notation string. If an error occurs when this method is being executed at the mobile device, the PLB AppEventGetPictError is generated and the error data is returned in ARG1.

  8.  

    The event numbers used in EVENTREG are:

     

    AppEventGetPict EQU 102 //Event number for EVENTREG

    AppEventGetPictError EQU 118 //Event number for EVENTREG

     

    The event result is defined as follows:

    AppEventGetPictError Event Data

    If an error occurs, the error event data is a string that is a message provided by the mobile device's native code.

    AppEventGetPict

    The success event data is a string that is based upon the 'destinationType' {option} parameter field. See link Cordova plug-in for more details.

     

    Value

    Event Data Returned is

    FILE_UR

    a string representing the image file location on local storage.

    DATA_URL

    a string containing the base64-encoded photo image.

    NATIVE_URI

    a native uri.

Sample Code

 

FileUrl DIM 250

Cl CLIENT

Opt INIT "{#"sourceType#": 1, #"destinationType#": 2}"

.

        EventReg Cl,AppEventGetPict,PictEvent,ARG1=FileUrl

.

       Cl.AppGetPicture Using "{#"cleanUp#": true }"

.

        Cl.AppGetPicture Using Opt

 

 

See Also: CLIENT, Client Methods, Method Syntax



PL/B Language Reference AppGetInfo Method (CLIENT) AppInstallOffLine Method (CLIENT)