Camera Examples

Example 1. Capture an image or video on the device

On the majority of devices and platforms, the code below may be used to take and save photos on the device. For legacy devices, please refer to Example 4, using the Windows Mobile RunProgramAndWait method.

vIntCaptureResult = Camera.CaptureImage();

IF(vIntCaptureResult == 0)
{

   vImageFileName = Camera.GetFileName();

   scribble1.LoadBitmapFile(vImageFileName);

// Save base64binary to the PHOTO table.

// Delete the image file after saving to the PHOTO table.

Note:

 

Camera.SetFileName("MyPicture.jpg");
Camera.SetPath("\My Documents\BrightProjects");

Camera.SetImageQuality(IMAGE_QUALITY_NORMAL);
Camera.SetResolution(100, 200);

Note:

Example 2. Use an existing Image or Video from Device

NOTE: This functionality is only available on iOS and Android devices

On modern devices, images or video files may also be retrieved via the camera roll. This will copy the image or video selected to a default or specified path as though the file was created via CaptureImage() or CaptureVideo() methods.

For example:

local.vResult = Camera.ImportImage();

IF(local.vResult == 0)
{

   local.vFileName = Camera.GetFileName();

   image1 = File.LoadBinary(local.vFileName);
}

Note:

 

Example 3. View Video File

NOTE: This functionality is only available on iOS and Android devices

Below is an example demonstrating setting up a custom image file name and path to record videos to. After the video has been captured, the code will trivially prompt the user to replay the video, using the Camera.ViewVideo() method.

// Check if custom path exists, else create it

local.vPath = System.GetProjectPath() & "/images/";

IF(File.FileExists(edtPath) <> true)

{

local.vResult = File.CreateDirectory(local.vPath);

IF(local.vResult <> 0)

{

Form.MessageBox("Error", "Directory could not be created", 0);

EXIT;

}

}

 

// Set path and file name for camera before starting

local.vFileName = "file.jpg";

Camera.SetPath(local.vPath);

Camera.SetFileName(local.vFileName);

 

// Capture video

local.vResult = Camera.CaptureVideo();

IF(local.vResult == 0)

{

// On success, prompt user and allow them to replay the video

local.vView = Form.MessageBox("Capture", "Video captured successfully - view?", MB_YESNO);

IF(local.vView == IDYES)

{

Camera.ViewVideo(local.vFileName);

}

}

Note:

Example 4. Run the Camera.exe using RunProgramAndWait method.

NOTE: This pattern may only be used if the device is Windows Mobile 4.x or lower

Before version 3.5.0., the RunProgramAndWait method was used to to run the camera application. But this procedure depends on the device used because different devices have different camera executables and have different ways to save the image file.

A HP device would have hpcamapp.exe while an i-Mate and an 02 XDA device would have camera.exe as the camera executable.

The image filename and path will also differ per device, for example: in an i-Mate JAMin device, the image path and filename is \My Documents\<CurrentDateTimestamp>00001\image_00000.jpg whereas in a HP device, photos are saved under \My Documents\My Pictures\image_0000.jpg.

Another issue with using RunProgramAndWait method is that programmatically it is not evident that a photo was taken, thus it is always an assumption that once the camera application is executed, a photo will be taken.  Therefore, to get the image filename and path, the expression has to loop through the possible image filenames i.e. image_0000.jpg, image_0001.jpg and so on. Another option to find the image filename is to use the Form.ShowFileOpenDialog, but this will not give a sense of automatic photo capture functionality.

The following image is an example of a Photo Capture form.

IF Settings.SettingDeviceUsed == 1

{

   // HP Device

   System.RunProgramAndWait("\Windows\hpcamapp.exe", "")

}

ELSE

{

   // iMate and XDA

   System.RunProgramAndWait("\Windows\Camera.exe", "")

}

 

// Find the image file created by the camera application.

// Save base64binary to the PHOTO table.

// Delete the image file after saving to the PHOTO table.

Note:

Example 4. Run the Camera.exe using RunProgramAndWait method.

NOTE: This pattern may only be used if the device is Windows Mobile 4.x or lower

Before version 3.5.0., the RunProgramAndWait method was used to to run the camera application. But this procedure depends on the device used because different devices have different camera executables and have different ways to save the image file.

A HP device would have hpcamapp.exe while an i-Mate and an 02 XDA device would have camera.exe as the camera executable.

The image filename and path will also differ per device, for example: in an i-Mate JAMin device, the image path and filename is \My Documents\<CurrentDateTimestamp>00001\image_00000.jpg whereas in a HP device, photos are saved under \My Documents\My Pictures\image_0000.jpg.

Another issue with using RunProgramAndWait method is that programmatically it is not evident that a photo was taken, thus it is always an assumption that once the camera application is executed, a photo will be taken.  Therefore, to get the image filename and path, the expression has to loop through the possible image filenames i.e. image_0000.jpg, image_0001.jpg and so on. Another option to find the image filename is to use the Form.ShowFileOpenDialog, but this will not give a sense of automatic photo capture functionality.

The following image is an example of a Photo Capture form.

IF Settings.SettingDeviceUsed == 1

{

   // HP Device

   System.RunProgramAndWait("\Windows\hpcamapp.exe", "")

}

ELSE

{

   // iMate and XDA

   System.RunProgramAndWait("\Windows\Camera.exe", "")

}

 

// Find the image file created by the camera application.

// Save base64binary to the PHOTO table.

// Delete the image file after saving to the PHOTO table.

Note: