Photo file format#
Photos can be saved in different file formats.
Camera 1#
Sample code to monitor photo file format:
/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?
/// Monitors and prints photo file format.
func monitorPhotoFileFormat(drone: Drone) {
cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
// called on main thread when the camera peripheral changes
if let camera = camera {
if camera.photoSettings.supportedFileFormats.isEmpty {
// setting value is not relevant if there is no supported value
print("No supported value")
} else {
// get setting value
let format = camera.photoSettings.fileFormat
print("Current value is: \(format)")
}
}
}
}
Example of output:
Current value is: JPEG
Current value is: DNG
Sample code to modify photo format:
/// Sets photo file format.
func setPhotoFileFormat(drone: Drone, fileFormat: CameraPhotoFileFormat) {
if let camera = drone.getPeripheral(Peripherals.mainCamera) {
// set setting value
camera.photoSettings.fileFormat = fileFormat
}
}
Trying to change the setting value to an unsupported value has no effect.
Values supported by the camera are provided by CameraPhotoSettings.supportedFileFormats
.
Camera 2#
Photo mode is configured with parameter Camera2Params.photoFileFormat
.
Sample code to monitor photo format:
/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?
// Monitors and prints photo file format.
func monitorPhotoFileFormat(drone: Drone) {
cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
// called on main thread when the camera peripheral changes
if let camera = camera {
// get configuration parameter
if let configParam = camera.config[Camera2Params.photoFileFormat] {
if configParam.currentSupportedValues.isEmpty {
// parameter value is not relevant
// if there is not supported values in current configuration
print("No supported value in current configuration")
} else {
// get parameter value
let fileFormat = configParam.value
print("Current value is: \(fileFormat)")
}
}
}
}
}
Example of output:
Current value is: jpeg
Current value is: dngAndJpeg
Sample code to modify photo format:
/// Sets photo file format.
func setPhotoFileFormat(drone: Drone, fileFormat: Camera2PhotoFileFormat) {
if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
// create configuration editor, starting from current configuration
let editor = camera.config.edit(fromScratch: false)
// retrieve configuration parameter
if let configParam = editor[Camera2Params.photoFileFormat] {
// 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 provided by the parameter field configParam.overallSupportedValues
.