使用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;
Run Code Online (Sandbox Code Playgroud)
//设置视频预览图层
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];
Run Code Online (Sandbox Code Playgroud)
//添加文本图层
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 …Run Code Online (Sandbox Code Playgroud)