ios - 通过 objective-c 模糊图像

标签 ios objective-c xcode

我想模糊应用程序的 UIImage, 你们有没有 Objective-C 方法来模糊图像?

我试图找到一种方法或技术,但找不到任何东西。请帮忙!

最佳答案

您可以使用核心图像过滤器。 http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html

看看 https://gist.github.com/betzerra/5988604 中的这个片段

//  Needs CoreImage.framework

- (UIImage *)blurredImageWithImage:(UIImage *)sourceImage{

    //  Create our blurred image
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage];

    //  Setting up Gaussian Blur
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:inputImage forKey:kCIInputImageKey];
    [filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];

    /*  CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches 
     *  up exactly to the bounds of our original image */
    CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];

    UIImage *retVal = [UIImage imageWithCGImage:cgImage];

    if (cgImage) {
        CGImageRelease(cgImage);
    }

    return retVal;
}

关于ios - 通过 objective-c 模糊图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28613713/

相关文章:

ios - 如何从 UIImagePicker 检测图像是否为横向

iphone - 如何在 iphone 中上传参数以及图像和音频

ios - xcode8中的 ionic 应用程序突然“拒绝连接到Firebase”

ios - 无法创建 xmpp muc 房间 : Code 503 (service unavailable)

iphone - Retina 中的 CGContextDrawImage 绘制像素化图像?

ios - 表格 View 未正确适应键盘

objective-c - 对于 objective-c 中的相同输入,每次都会生成不同的 HMac 摘要

objective-c - --deep 标志有什么作用?

c++ - 我可以用结构 vector 构建一个结构 vector vector 吗? (对真的)

ios - 如何知道数组计数是否在 didUpdateLocations Swift 中增加