takePhoto method
Future<Uint8List>
takePhoto({
- int? autofocusSeconds = 3,
- PhotoQuality quality = PhotoQuality.medium,
- AutoFocusType autofocusType = AutoFocusType.average,
Takes a photo with the camera.
Args: autofocusSeconds (int?): The number of seconds to autofocus. Defaults to 3. quality (PhotoQuality): The quality of the photo. Defaults to PhotoQuality.medium. autofocusType (AutoFocusType): The type of autofocus. Defaults to AutoFocusType.average.
Returns: Future
Throws: Exception: If the photo capture fails.
Implementation
Future<Uint8List> takePhoto({
int? autofocusSeconds = 3,
PhotoQuality quality = PhotoQuality.medium,
AutoFocusType autofocusType = AutoFocusType.average,
}) async {
if (!frame.useLibrary) {
throw Exception("Cannot take photo via SDK without library helpers");
}
if (!isAwake) {
await frame.runLua("frame.camera.wake()", checked: true);
await Future.delayed(const Duration(milliseconds: 500));
isAwake = true;
}
final response =
frame.bluetooth.waitForDataOfType(FrameDataTypePrefixes.photoData);
await frame.runLua(
"cameraCaptureAndSend(${quality.value},${autofocusSeconds ?? 'nil'},'${autofocusType.name}')");
final imageBuffer = await response;
if (imageBuffer.isEmpty) {
throw Exception("Failed to get photo");
}
if (autoProcessPhoto) {
return processPhoto(imageBuffer, autofocusType);
}
return imageBuffer;
}