takePicture method
Take a picture and return the bytes in callback.
The default output is for a JPEG image.
This should only be called after passing as a parameter to a CameraController and CameraController.initialize has been called.
Implementation
@override
Future<void> takePicture(ImageCallback callback) async {
verifyAttached();
final CapturePhotoSettings oldSettings = nextPhotoSettings;
nextPhotoSettings = _createNextPhotoSettings();
photoCaptureDelegate = CapturePhotoCaptureDelegate(
didFinishProcessingPhoto: (CapturePhoto photo) {
final Uint8List? photoData = photo.fileDataRepresentation;
if (photoData == null) {
throw ArgumentError.value(
photo.fileDataRepresentation,
'photo.fileDataRepresentation',
'Byte data returned empty. This could be due to the video codec type.',
);
} else {
callback(photoData);
}
},
);
await capturePhotoOutput.capturePhotoWithSettings(
oldSettings,
photoCaptureDelegate,
);
}