Page History
Use the camera on mobile device to take photos or access the photo library on mobile device.
Properties
Source
An enum value indicates where the image is sourced. Valid options:
CAM: take photo from camera
LIB: select photo from photo library
EnableImage
A Boolean value indicates if enable or disable the device to take a photo.
EnableVideo
A Boolean value indicates if enable or disable the device to take a video.
SaveToPhotoGallery
A Boolean value indicates if the photo should be saved to the gallery.
ReturnBase64String
A Boolean value indicates if return the image data as a base64 encoded string.
ReturnFile
A Boolean value specifies whether return the path and URL of the image or video file.
AllowEdit
A Boolean value indicates whether allow users to do some editing on the image or video clip like scaling. The editing features are device specific.
EnableAnnotation
A Boolean value indicates whether allow annotation on photo taken from camera or album
VideoQuality
An enum value to select quality level of the video. Valid options:LOW,MED,HIGH
VideoMaxDuration
An integer value specifies the limit length of video to this number of seconds. Set value to 0 for no maximum.
OutputPath
A string value specifies a fully qualified path of the file that will be created by the camera.
OutputFile (READONLY)
A string value contains the logical path of the image or video file.
OutputUrl (READONLY)
A string value contains the URL of the image or video file
IsImage (READONLY)
A Boolean value that tell user if an image has been taken
IsVideo (READONLY)
A Boolean value that tell user if a video has been recorded.
ImageAsBase64Data (READONLY)
A string value that contains the image data encoded as base64.
Methods
ActivateCamera
Activate the camera on the device.
- Input Arguments: None
- Output Argument: None.
- Return Value: Status Code
SetImageSize
Set the size of image. For actual image size, set width and height to 0.
Input Arguments:
Name
Type
Mandatory
Description
Orientation
Enum
Yes
Specify whether the size applies to a specific orientation. If so, the size will be flipped for the alternate orientation.
Valid values are: BOTH, PORT, LANDWidth
Integer
Yes
Image width
Height
Integer
Yes
Image height
|
- Output Argument: None.
- Return Value: None.
SetBase64ImageSize
Specify the size of the image when it is encoded for base64. To use the image size settings, set width and height to 0.
Input Arguments:
|Name
Type
Mandatory
Description
Orientation
Enum
Yes
Specify whether the size applies to a specific orientation. If so, the size will be flipped for the alternate orientation.
Valid values are: BOTH, PORT, LANDWidth
Integer
Yes
Image width
Height
Integer
Yes
Image height
- Output Argument: None.
- Return Value: None.
Events
Completed
Triggered when an image/video has been taken/recorded.
- Parameters:|
Name
Type
Description
Status
Enum
See Status Code
Message
String
Code Examples
Recommended code: If taking a video, return the data as a file (ReturnFile := true) and set ReturnBase64String to false.
Define_Com Class(#xDeviceCamera) Name(#CameraUse)
Evtroutine Handling(#COM_OWNER.Initialize)
...
#ActivateCamera.Enabled := false
Endroutine
Evtroutine Handling(#CameraUse.Initialize)
...
#ActivateCamera.Enabled := true
Endroutine
Evtroutine Handling(#ActivateCamera.Click)
...
#CameraUse.Source :=
...
CAM
#CameraUse.EnableImage :=
...
true
#CameraUse.EnableVideo :=
...
false
#CameraUse.SetImageSize( PORT #ImageSizeWidth.Value.AsInteger #ImageSizeHeight.Value.AsInteger
...
)
#CameraUse.SaveToPhotoGallery :=
...
true
#CameraUse.ReturnBase64String :=
...
true
#CameraUse.SetBase64ImageSize( PORT #Base64Width.Value.AsInteger #Base64Height.Value.AsInteger
...
)
#CameraUse.ReturnFile :=
...
true
#CameraUse.AllowEdit :=
...
false
#CameraUse.EnableAnnotation :=
...
true
#CameraUse.VideoQuality :=
...
HIGH
#CameraUse.VideoMaxDuration := #VideoMaxDuration.Value.AsNumber
...
#CameraUse.OutputPath :=
...
#OutputPath
#CameraUse.ActivateCamera()
Endroutine
Evtroutine Handling(#CameraUse.Completed) Status(#lstatus) Message(#message)
...
If (#lstatus = OK)
...
#GeneratedFile := #CameraUse.OutputFile
...
#GeneratedFileUrl := #CameraUse.OutputUrl
...
If (#CameraUse.IsImage)
...
#GeneratedType := 'Image'
...
Else
#GeneratedType := 'Video'
Endif
If (#CameraUse.ImageAsBase64Data <> "")
...
#Base64 := #CameraUse.ImageAsBase64Data
...
#LastImage.FileName := "data:image/png;base64," + #CameraUse.ImageAsBase64Data
...
Endif
Else
#Status := #message
Endif
#Status := #lstatus
Endroutine
Write to a local file (xDeviceFileWrite)
Define_Com Class(#xDeviceFileWrite) Name(#FileWriter
Evtroutine Handling(#COM_OWNER.Initialize)
...
#Write.Enabled := false
Endroutine
Evtroutine Handling(#FileWriter.Initialize)
...
#Write.Enabled := true
Endroutine
Evtroutine Handling(#Write.Click)
...
#FileWriter.FileName := '/recipes/appleStrudel'
...
#FileWriter.FileType :=
...
BIN
#FileWriter.FileEncoding :=
...
UTF8
#FileWriter.DataEncoding :=
...
BASE64
#FileWriter.Data := 'Add 3 eggs and 4 cups of sugar'
...
#FileWriter.Write()
Endroutine
Evtroutine Handling(#FileWriter.Completed) Status(#returnedStatus) Message(#message)
...
#Status :=
...
#returnedStatus
If (#Status <> OK)
...
#StatusMessage :=
...
#message
Endif
Endroutine
Read a local file (xDeviceFileRead
Define_Com Class(#xDeviceFileRead) Name(#FileReader)
Evtroutine Handling(#COM_OWNER.Initialize)
...
#Read.Enabled := false
Endroutine
Evtroutine Handling(#FileReader.Initialize)
...
#Read.Enabled := true
Endroutine
Evtroutine Handling(#Read.Click)
...
#FileReader.FileName := '/recipes/chocolateCake'
...
#FileReader.FileType :=
...
TEXT
#FileReader.FileEncoding :=
...
UTF8
#FileReader.DataEncoding :=
...
NONE
#FileReader.Read()
Endroutine
Evtroutine Handling(#FileReader.Completed) Status(#returnedStatus) Data(#returnedData) Message(#message)
...
#Status :=
...
#returnedStatus
If (#Status = OK)
...
#Data :=
...
#returnedData
Else
#StatusMessage := #message
Endif
Endroutine