CIBumpDistortion 濾鏡效果如下
先看參數(shù):
CIFilter *filter = [CIFilter filterWithName:@"CIBumpDistortion"];
NSLog(@"%@ - %@", filterName, filter.attributes);
inputCenter = {
CIAttributeClass = CIVector;
CIAttributeDefault = "[150 150]";
CIAttributeDescription = "The center of the effect as x and y coordinates.";
CIAttributeDisplayName = Center;
CIAttributeType = CIAttributeTypePosition;
};
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 = 300;
CIAttributeDescription = "The radius determines how many pixels are used to create the distortion. The larger the radius, the wider the extent of the distortion.";
CIAttributeDisplayName = Radius;
CIAttributeMin = 0;
CIAttributeSliderMax = 600;
CIAttributeSliderMin = 0;
CIAttributeType = CIAttributeTypeDistance;
};
inputScale = {
CIAttributeClass = NSNumber;
CIAttributeDefault = "0.5";
CIAttributeDescription = "The scale of the effect determines the curvature of the bump. A value of 0.0 has no effect. Positive values create an outward bump; negative values create an inward bump.";
CIAttributeDisplayName = Scale;
CIAttributeIdentity = 0;
CIAttributeSliderMax = 1;
CIAttributeSliderMin = "-1";
CIAttributeType = CIAttributeTypeScalar;
};
所以這個濾鏡除了image以外還需要以下參數(shù):
- inputCenter:中心點,默認值[150, 150]
- inputRadius:半徑,默認值300趋厉,范圍0~600
- inputScale:曲率窥翩,默認值0.5代赁,范圍-1~1,正直外凸蔫骂,負值內(nèi)凹
實例
代碼
CIFilter *filter = [CIFilter filterWithName:@"CIBumpDistortion"];
CIContext *context = [CIContext contextWithOptions:nil];
NSLog(@"%@ - %@", filterName, filter.attributes);
if (filter.attributes[kCIInputImageKey]) {
[filter setValue:inputImage forKey:kCIInputImageKey];
if (filter.attributes[kCIInputCenterKey]) {
[filter setValue:[CIVector vectorWithX:self.image.size.width / 2 Y:self.image.size.height / 2] forKey:kCIInputCenterKey];
}
if (filter.attributes[kCIInputRadiusKey]) {
[filter setValue:@(50) forKey:kCIInputRadiusKey];
}
if (filter.attributes[kCIInputScaleKey]) {
[filter setValue:@(0.8) forKey:kCIInputScaleKey]; // 外凸
// [filter setValue:@(0.8) forKey:kCIInputScaleKey]; // 內(nèi)凹
}
CIImage *outPutImage = filter.outputImage;
CGImageRef imageRef = [context createCGImage:outPutImage fromRect:outPutImage.extent];
if (imageRef) {
return [UIImage imageWithCGImage:imageRef];
}
}
return nil;