//色调调整
+ (UIImage *)sepiaToneWithImage:(UIImage *)image intensity:(CGFloat)value {
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *cImage = [CIImage imageWithCGImage:image.CGImage];
CIImage *cResultImage;
CIFilter *sepiaTone = [CIFilter filterWithName:@"CISepiaTone"];
[sepiaTone setValue:cImage forKey:@"inputImage"];
[sepiaTone setValue:@(value) forKey:@"inputIntensity"];
cResultImage = [sepiaTone valueForKey:@"outputImage"];
CGImageRef imageRef = [context createCGImage:cResultImage fromRect:[cResultImage extent]];
UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
CFRelease(imageRef);
return resultImage;
}
//高斯模糊
+ (UIImage *)gaussianBlurWithImage:(UIImage *)image radius:(CGFloat)value {
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *cImage = [CIImage imageWithCGImage:image.CGImage];
CIImage *cResultImage;
CIFilter *gaussianBlur = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlur setValue:cImage forKey:@"inputImage"];
[gaussianBlur setValue:@(value * 10) forKey:@"inputRadius"];
cResultImage = [gaussianBlur valueForKey:@"outputImage"];
CGImageRef imageRef = [context createCGImage:cResultImage fromRect:[cResultImage extent]];
UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
CFRelease(imageRef);
return resultImage;
}
网友评论