Photo file format#

Photos can be saved in different file formats.

Camera 1#

Sample code to monitor photo file format:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints photo file format. */
fun monitorPhotoFileFormat(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.photo()?.run {
            if (supportedFileFormats().isEmpty()) {
                // setting value is not relevant if there is no supported value
                println("No supported value")
            } else {
                // get setting value
                val fileFormat = fileFormat()
                println("Current value: $fileFormat")
                // updating flag
                println("Updating: $isUpdating")
            }
        }
    }
}

Example of output:

Current value: JPEG
Updating: true

Sample code to modify photo format:

/** Sets photo file format. */
fun setPhotoFileFormat(drone: Drone, fileFormat: CameraPhoto.FileFormat) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        photo().setFileFormat(fileFormat)
    }
}

Trying to change the setting value to an unsupported value has no effect. Values supported by the camera are provided by CameraPhoto.Setting.supportedFileFormats().

Camera 2#

Photo mode is configured with parameter Camera.Config.PHOTO_FILE_FORMAT.

Sample code to monitor photo file format:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints photo file format. */
fun monitorPhotoFileFormat(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.run {
            // get configuration parameter
            config[Camera.Config.PHOTO_FILE_FORMAT].run {
                if (supportedValues(onlyCurrent = true).isEmpty()) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("No supported value in current configuration")
                } else {
                    println("Current value: $value")
                }
            }
        }
    }
}

Example of output:

Current value: JPEG

Sample code to modify photo format:

/** Sets photo file format. */
fun setPhotoFileFormat(drone: Drone, fileFormat: Camera.PhotoFileFormat) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.PHOTO_FILE_FORMAT].let { configParam ->
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = fileFormat
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are retrieved by calling configParam.supportedValues(onlyCurrent = false).