0

カスタムカメラアプリを構築しようとしています。

タスク:

  1. ライブ画像プレビューを表示します。
  2. 画面の任意の場所をタップして画像をキャプチャできます。
  3. 結果の画像をライブ画像プレビューの上に表示します。

現在、タスク 1 を除いてすべてが機能します。カメラが動作していて、画面をタップすると画像が表示されても、ライブ画像プレビューを含むビューは背景色のままです (背景色が選択されていない場合は透明のままです)。何か案は?この以前のディスカッションを参照しましたが、すべてのベースをカバーしていると思います: AVFoundation カメラ プレビュー レイヤーが機能しない

私は何が欠けていますか?

-(void)viewWillAppear:(BOOL)animated{
    session = [[AVCaptureSession alloc] init];
    [session setSessionPreset:AVCaptureSessionPresetPhoto];

    AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error;
    AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];

    if ([session canAddInput:deviceInput]) {
        [session addInput:deviceInput];
    }
    AVCaptureVideoPreviewLayer *previewlayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    [previewlayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    CALayer *rootLayer = [[self view] layer];
    [rootLayer setMasksToBounds:YES];
    CGRect frame = self.frameforCapture.frame;

    [previewlayer setFrame:frame];

    [rootLayer insertSublayer:previewlayer atIndex:0];

    stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
    [stillImageOutput setOutputSettings:outputSettings];

    [session addOutput:stillImageOutput];

    [session startRunning];
    //....
}
4

0 に答える 0