On iOS, I use the capture code from AVCaptureStillImageOutput, this way:
[_ captureStillOutput captureStillImageAsynchronouslyFromConnection: _captureConnection completeHandler: asyncCaptureCompletionHandler];
to simplify folding my code, my asyncCaptureCompletionHandler block looks like this:
void(^asyncCaptureCompletionHandler)(CMSampleBufferRef imageDataSampleBuffer, NSError *error) =
^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (CMSampleBufferIsValid(imageDataSampleBuffer)) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
}
}
I went through all my code and cross-referenced stack overflows and found no suggestion that a valid fetch buffer would be captured without proper JPEG.
_captureStillOutput = [[AVCaptureStillImageOutput alloc] init];
_captureStillOutput.outputSettings =
[NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey,
nil];
if ([session canAddOutput:_captureStillOutput]) {
[session addOutput:_captureStillOutput];
}
:
* - "NSInvalidArgumentException", : "* + [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - jpeg. '
google " jpeg" . . .