美文网首页
色调调整与高斯模糊

色调调整与高斯模糊

作者: being_sun | 来源:发表于2018-05-14 14:44 被阅读0次
    //色调调整
    + (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;
    }
    

    相关文章

      网友评论

          本文标题:色调调整与高斯模糊

          本文链接:https://www.haomeiwen.com/subject/lqxjdftx.html