2016-10-05 27 views
4

私は自分のアプリからキャプチャイメージとビデオを実装しようとしていますが、現在はiOS 10以降から"AVCaptureStillImageOutput"は推奨されていません。iOS 10 - Objective-C:AVCapturePhotoOutput()を実装して画像や動画をキャプチャする方法は?

Objective-CのAVCapturePhotoOutputを実装する際に助けてください。

_avCaptureOutput = [[AVCapturePhotoOutput alloc]init]; 
_avSettings = [AVCapturePhotoSettings photoSettings]; 


AVCaptureSession* captureSession = [[AVCaptureSession alloc] init]; 
[captureSession startRunning]; 



AVCaptureConnection *connection = [self.movieOutput connectionWithMediaType:AVMediaTypeVideo]; 

if (connection.active) 
{ 
    //connection is active 
    NSLog(@"Connection is active"); 

    id previewPixelType = _avSettings.availablePreviewPhotoPixelFormatTypes.firstObject; 
    NSDictionary *format = @{(NSString*)kCVPixelBufferPixelFormatTypeKey:previewPixelType,(NSString*)kCVPixelBufferWidthKey:@160,(NSString*)kCVPixelBufferHeightKey:@160}; 

    _avSettings.previewPhotoFormat = format; 

    [_avCaptureOutput capturePhotoWithSettings:_avSettings delegate:self]; 


} 
else 
{ 
    NSLog(@"Connection is not active"); 
    //connection is not active 
    //try to change self.captureSession.sessionPreset, 
    //or change videoDevice.activeFormat 
} 
+0

AVCapturePhotoOutputの目的は何ですか? –

+0

あなたは 'AVCapturePhotoCaptureDelegate'を実装しましたか? – ricardopereira

+0

'self.movi​​eOutput'はどのようなタイプですか? – ricardopereira

答えて

4
_avCaptureOutput = [[AVCapturePhotoOutput alloc]init]; 
_avSettings = [AVCapturePhotoSettings photoSettings]; 

AVCaptureSession* captureSession = [[AVCaptureSession alloc] init]; 
[captureSession startRunning]; 

[self.avCaptureOutput capturePhotoWithSettings:self.avSettings delegate:self]; 

自己イメージを取得し、今AVCapturePhotoCaptureDelegate

#pragma mark - AVCapturePhotoCaptureDelegate 
-(void)captureOutput:(AVCapturePhotoOutput *)captureOutput didFinishProcessingPhotoSampleBuffer:(CMSampleBufferRef)photoSampleBuffer previewPhotoSampleBuffer:(CMSampleBufferRef)previewPhotoSampleBuffer resolvedSettings:(AVCaptureResolvedPhotoSettings *)resolvedSettings bracketSettings:(AVCaptureBracketedStillImageSettings *)bracketSettings error:(NSError *)error 
{ 
    if (error) { 
     NSLog(@"error : %@", error.localizedDescription); 
    } 

    if (photoSampleBuffer) { 
     NSData *data = [AVCapturePhotoOutput JPEGPhotoDataRepresentationForJPEGSampleBuffer:photoSampleBuffer previewPhotoSampleBuffer:previewPhotoSampleBuffer]; 
     UIImage *image = [UIImage imageWithData:data]; 
    } 
} 

を実装し、あなたがやりたいする必要があります。

は、ここに私のサンプルコードです。

+0

本当に簡単な実装 –

+0

これからどのようにプレビュー写真を手に入れますか? – user2995344

関連する問題