1

我基本上是想让“匿名面孔过滤器配方”示例在 iOS 模拟器中工作。

没有错误或警告,但似乎“CISourceOverCompositing”过滤器没有按预期工作。在 maskImage 上绘制的圆圈是破坏性的,而不是相加的。例如,如果找到 5 个面,则绘制 5 个圆圈,但在 maskImage 上只显示最后一个。

我怎样才能使每个圆圈以加法方式绘制到 maskImage ?

这是我用来构建掩码的代码:

// Create a green circle to cover the rects that are returned.
CIImage *maskImage = nil;
for (CIFeature *f in faces){
    CIVector *circleCenter = [CIVector vectorWithX:f.bounds.origin.x+f.bounds.size.width/2.0 Y:f.bounds.origin.y+f.bounds.size.height/2.0];
    CGFloat circleRadius = MIN([f bounds].size.width, [f bounds].size.height)/1.5;
    CIFilter *radialGradient = [CIFilter filterWithName:@"CIRadialGradient" keysAndValues:
                                @"inputRadius0", [NSNumber numberWithFloat:circleRadius],
                                @"inputRadius1", [NSNumber numberWithFloat:circleRadius+1.0f],
                                @"inputColor0", [CIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0],
                                @"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],
                                @"inputCenter", circleCenter, nil];
    CIImage *circleImage = [radialGradient valueForKey:@"outputImage"];
    if (maskImage == nil) {
        maskImage = circleImage;
    } else {
        maskImage = [[CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues:@"inputImage", circleImage, @"inputBackgroundImage",maskImage, nil] valueForKey:@"outputImage"];
    }
}
4

1 回答 1

4

不幸的是,在Anonymous Faces Filter Recipe上找到的源代码没有立即编译或工作。CISourceOverCompositing过滤器的问题可以通过inputColor1参数和 alpha 通道找到。用以下颜色替换inputColor1颜色,你应该很高兴:

@"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]

于 2014-04-05T20:43:18.743 回答