AVCaptureStillImageOutput、特にcaptureStillImageAsynchronouslyFromConnectionはどのように使用しますか?
-
26-09-2019 - |
質問
次の完了ハンドラーを設定するにはどうすればよいですか:
CaptureStillImageAsynchronouslyFromConnection:completionHandler:
AVキャプチャ静止画出力用?
- (void)captureDelegate:(CMSampleBufferRef)バッファ エラー:(NSError *)エラー;
?
解決
ブロックを使用します。このようなもの:
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(captureStillImageFailedWithError:)]) {
[delegate captureStillImageFailedWithError:error];
}
}
}];
[library release];
[image release];
} else if (error) {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(captureStillImageFailedWithError:)]) {
[delegate captureStillImageFailedWithError:error];
}
}
}];
所属していません StackOverflow