10

UIImagePickerコントローラーまたはAVFoundationのいずれかを使用して、カメラ出力だけでなくオーバーレイサブビューも記録する必要があるビデオをキャプチャまたは記録する必要があります。オーバーレイ画像をカメラプレビューに追加する例をたくさん見てきましたが、必要なのはオーバーレイ画像やテキストプレビューだけでなく、最終的なビデオ出力でのオーバーレイの実際の記録です。

//グラフィカルレイヤーを追加します

 CALayer *theDonut = [CALayer layer];
 theDonut.bounds = CGRectMake(50,50, 150, 150);
 theDonut.cornerRadius = 50/2;
 theDonut.backgroundColor = [UIColor clearColor].CGColor;
 theDonut.borderWidth = 50/5;
 theDonut.borderColor = [UIColor orangeColor].CGColor;

//ビデオプレビューレイヤーを設定します

videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:capSession];
videoPreviewLayer.frame = videoPreview.bounds;
videoPreviewLayer.backgroundColor = [UIColor blackColor].CGColor;
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

videoPreview.layer.masksToBounds = YES;
[videoPreview.layer addSublayer:videoPreviewLayer];
[videoPreview.layer addSublayer:theDonut];

//テキストレイヤーを追加します

UIFont *font = [UIFont fontWithName:@"MarkerFelt-Thin" size:40.0];
    CGSize maxSize = CGSizeMake(480, 10000.0);
    CGSize labelSize = [@"Test Text" sizeWithFont:font constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
    CGRect labelFrame = CGRectMake(50.0, 10.0, labelSize.width, labelSize.height);
    UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
    label.font = font;
    label.text = @"Test Text";
    label.numberOfLines = 0;
    [videoPreview addSubview:label];

//ボタンオーバーレイも追加します!!!

    UIButton *snap = [UIButton buttonWithType:UIButtonTypeCustom];
    [snap setImage:[UIImage imageNamed:@"takePic"]
          forState:UIControlStateNormal];
    [snap addTarget:self
             action:@selector(pickerCameraSnap:)
   forControlEvents:UIControlEventTouchUpInside];
    snap.frame = CGRectMake(74, 370, 178, 37);

    [videoPreview addSubview:snap];

    // 8) Commit session configuration
    // 9) Start running capture session
    // ========================================
    [capSession commitConfiguration];
    [capSession startRunning];


    //Make sure video is not recording
    [[videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];

この例は、このサンプルコードから変更されています-ビデオプレビューにテキストと描画を追加しますが、最終的な出力ファイルには記録しません。

http://ioscoreframeworks.com/assets/code/DemoCapture.zip

4

1 に答える 1

0

WWDC 2010 Sample Code に含まれている AVEditdemo アプリケーションを試すことができます。残念ながら、WWDC 2010 サンプル コードをすべてダウンロードして入手する必要があります (232.6mb)。ここからすべてのコードを完全にダウンロードできます: http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?code=y&source=x&bundleID=20645

于 2013-04-24T12:18:57.350 に答える