我有一个带摄像头的iPhone应用程序,我正在尝试将滤镜应用于视频输入并在屏幕上显示已过滤的视频。
我考虑将方法captureOutput上的过滤器应用为:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
keysAndValues:kCIInputImageKey,
image, @"inputIntensity",
[NSNumber numberWithFloat:0.8],
nil];
videoCALayer.filters = [NSArray arrayWithObject:filter];
[videoCALayer setValue:[NSNumber numberWithInt:1] forKeyPath:@"filters.CISepiaTone.inputScale"];
}
我正在尝试设置backgroundFilters数组,然后为CALayer设置第一个过滤器,但它不起作用,任何人都可以建议它是如何完成的?感谢。