美文网首页
iOS UIImage生成高性能圆角图片

iOS UIImage生成高性能圆角图片

作者: 魔力双鱼 | 来源:发表于2019-03-13 18:16 被阅读0次
  • (void)imageWihtSize:(CGSize)size radius:(CGFloat)radius backColor:(UIColor *)backColor completion:(void(^)(UIImage *image))completion{
    // 异步绘制裁切
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    // 利用绘图建立上下文
    UIGraphicsBeginImageContextWithOptions(size, true, 0);
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    // 填充颜色
    [backColor setFill];
    UIRectFill(rect);
    // 贝塞尔裁切
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
    [path addClip];
    [self drawInRect:rect];

      // 获取结果
      UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
      // 关闭上下文
      UIGraphicsEndImageContext();
      // 主队列回调
      dispatch_async(dispatch_get_main_queue(), ^{
          completion(resultImage);
      });
    

    });
    }

切圆角
iOS设置圆角的四种方法
iOS离屏渲染之优化分析

相关文章

网友评论

      本文标题:iOS UIImage生成高性能圆角图片

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