5
AVFoundationを使用してカメラを実装しようとしています。私はすべてが正しいと思う。これは私がAVFoundationカメラプレビューレイヤーが機能しない
- をやっているものですにセッション
- を作成バック
- にカメラを取得するための装置を介してビデオタイプ
- ループのデバイスを取得する#3で述べたデバイスを使用して、デバイスの入力を取得し、 CALayerのあちこちを取得 をセッション
- に追加するタイプ
AVCaptureStillImageOutput
- セットの出力設定の出力を作成し、セッションに追加私の見解2を
- は7
- スタートがセッションを
だから、実行している#で述べた層に追加AVCaptureVideoPreviewLayer
self.session = [[AVCaptureSession alloc]init];
[self.session setSessionPreset:AVCaptureSessionPresetHigh];
NSArray *devices = [[NSArray alloc]init];
devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices){
if([device position] == AVCaptureDevicePositionBack){
self.device = device;
break;
}
}
NSError *error;
self.input = [[AVCaptureDeviceInput alloc]initWithDevice:self.device error:&error];
if([self.session canAddInput:self.input]){
[self.session addInput:self.input];
}
self.stillImageOutput = [[AVCaptureStillImageOutput alloc]init];
NSDictionary *outputSettings = @{AVVideoCodecKey : AVVideoCodecJPEG};
[self.stillImageOutput setOutputSettings:outputSettings];
[self.session addOutput:self.stillImageOutput];
CALayer *cameraLayer = self.cameraView.layer;
self.cameraView.backgroundColor = [UIColor clearColor];
AVCaptureVideoPreviewLayer *preview = [[AVCaptureVideoPreviewLayer alloc]initWithSession:self.session];
[cameraLayer addSublayer:preview];
[self.session startRunning];
私は何を取得するビュー1(それはその背景としての.pngイメージを持っているその下に表示するように画像が穴を有し、ビュー2が見えるようにすることができます。ここでは
コードです)とビュー2が表示されますが、私は私が何を想定していないか分かりません。私はビュー2の背景色をクリアカラーに変更したので、私はすべて黒を見ます。私はカメラが見ているものを見るはずです。