美文网首页
color转换image

color转换image

作者: Ice丶泽 | 来源:发表于2016-11-02 11:49 被阅读0次

该方法主要用于将 UIColor 转化为 UIImage ,用于项目中,放在代码块中,方便使用

- (UIImage *)imageWithColor:(UIColor *)color{   
 // 描述矩形
    CGRect rect           = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);      
 // 开启位图上下文
    UIGraphicsBeginImageContext(rect.size);
 // 获取位图上下文
    CGContextRef context  = UIGraphicsGetCurrentContext();    
// 使用color演示填充上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);    
// 渲染上下文
    CGContextFillRect(context, rect);    
// 从上下文中获取图片
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();    
// 结束上下文
    UIGraphicsEndImageContext();    return theImage;
}

相关文章

网友评论

      本文标题:color转换image

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