CIEdgeWork 濾鏡效果如下
先看參數(shù):
CIFilter *filter = [CIFilter filterWithName:@"CIEdgeWork"];
NSLog(@"%@ - %@", filterName, filter.attributes);
inputImage = {
CIAttributeClass = CIImage;
CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
CIAttributeDisplayName = Image;
CIAttributeType = CIAttributeTypeImage;
};
inputRadius = {
CIAttributeClass = NSNumber;
CIAttributeDefault = 3;
CIAttributeDescription = "The thickness of the edges. The larger the value, the thicker the edges.";
CIAttributeDisplayName = Radius;
CIAttributeMin = 0;
CIAttributeSliderMax = 20;
CIAttributeSliderMin = 0;
CIAttributeType = CIAttributeTypeDistance;
};
所以這個(gè)濾鏡除了image以外還需要以下參數(shù):
- inputRadius:厚度,默認(rèn)值3隆判,范圍0~20
實(shí)例
代碼
CIFilter *filter = [CIFilter filterWithName:@"CIEdgeWork"];
CIContext *context = [CIContext contextWithOptions:nil];
NSLog(@"%@ - %@", filterName, filter.attributes);
if (filter.attributes[kCIInputImageKey]) {
[filter setValue:inputImage forKey:kCIInputImageKey];
if (filter.attributes[kCIInputRadiusKey]) {
NSNumber *radius = @([filter.attributes[kCIInputRadiusKey][kCIAttributeSliderMax] integerValue] / 10);
[filter setValue:radius forKey:kCIInputRadiusKey];
}
CIImage *outPutImage = filter.outputImage;
CGImageRef imageRef = [context createCGImage:outPutImage fromRect:outPutImage.extent];
if (imageRef) {
return [UIImage imageWithCGImage:imageRef];
}
}
return nil;