zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    php的form中元素name属性相同时的取值问题
    从FCN到DeepLab
    论文学习:Fully Convolutional Networks for Semantic Segmentation
    笔记:基于DCNN的图像语义分割综述
    论文笔记(3):STC: A Simple to Complex Framework for Weakly-supervised Semantic Segmentation
    概念:弱监督学习
    FCN小小实战
    (2)Deep Learning之线性单元和梯度下降
    (1)Deep Learning之感知器
    深度学习实验系列(1)
  • 原文地址:https://www.cnblogs.com/417460188dy/p/4580925.html
Copyright © 2011-2022 走看看