当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS开发 UIImage生成高性能圆角图片教程

iOS开发 UIImage生成高性能圆角图片教程

2018年01月02日  | 移动技术网IT编程  | 我要评论

保定天气,反斗天庭主题曲,难忘的第一次作文500字

iOS开发 UIImage生成高性能圆角图片教程。

- (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);
        });
    });
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网