美文网首页
修改图片的透明度

修改图片的透明度

作者: InitWithYou | 来源:发表于2016-09-22 10:52 被阅读108次

    修改图片的透明度

    - (UIImage *)imageByApplyingAlpha:(CGFloat)alpha image:(UIImage*)image
    {
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
        
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
        
        CGContextScaleCTM(ctx, 1, -1);
        CGContextTranslateCTM(ctx, 0, -area.size.height);
        
        CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
        
        CGContextSetAlpha(ctx, alpha);
        
        CGContextDrawImage(ctx, area, image.CGImage);
        
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        return newImage;
    }
    

    相关文章

      网友评论

          本文标题:修改图片的透明度

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