• IOS 毛玻璃化图片


    + (UIImage *)blurWithCoreImage:(UIImage *)sourceImage withFrame:(CGRect)frame

    {

        CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage];

        

        // Apply Affine-Clamp filter to stretch the image so that it does not look shrunken when gaussian blur is applied

        CGAffineTransform transform = CGAffineTransformIdentity;

        CIFilter *clampFilter = [CIFilter filterWithName:@"CIAffineClamp"];

        [clampFilter setValue:inputImage forKey:@"inputImage"];

        [clampFilter setValue:[NSValue valueWithBytes:&transform objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];

        

        // Apply gaussian blur filter with radius of 30

        CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];

        [gaussianBlurFilter setValue:clampFilter.outputImage forKey: @"inputImage"];

        [gaussianBlurFilter setValue:@3 forKey:@"inputRadius"];

        

        CIContext *context = [CIContext contextWithOptions:nil];

        CGImageRef cgImage = [context createCGImage:gaussianBlurFilter.outputImage fromRect:[inputImage extent]];

        

        // Set up output context.

        UIGraphicsBeginImageContext(frame.size);

        CGContextRef outputContext = UIGraphicsGetCurrentContext();

        CGContextScaleCTM(outputContext, 1.0, -1.0);

        CGContextTranslateCTM(outputContext, 0, - frame.size.height);

        

        // Draw base image.

        CGContextDrawImage(outputContext, frame, cgImage);

        

        // Apply white tint

        CGContextSaveGState(outputContext);

        CGContextSetFillColorWithColor(outputContext, [UIColor colorWithWhite:1 alpha:0.2].CGColor);

        CGContextFillRect(outputContext, frame);

        CGContextRestoreGState(outputContext);

        

        // Output image is ready.

        UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();

        CGImageRelease(cgImage);

        

        UIGraphicsEndImageContext();

        

        return outputImage;

    }

  • 相关阅读:
    微软API集
    如何在Visual Studio.net中让同一解决方案中包含多个不同类型的项目并共享同一命名空间
    总结:Asp.net页面之间传递参数的几种方法
    Javascript 鼠标滑过显示大图的效果
    HttpContext.Current.Session["key"]取值
    数字金额转大写
    整合多个图片到一个pdf
    .net reflector & disassembler
    yacc grammar for a simple shell
    Windows cmd编码
  • 原文地址:https://www.cnblogs.com/417460188dy/p/4580925.html
Copyright © 2020-2023  润新知