用色值生成图片

Posted 黄镇威

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用色值生成图片相关的知识,希望对你有一定的参考价值。

  1. @interface UIImage (Color)  
  2.   
  3. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;  
  4.   
  5. @end  
  6.   
  7. @implementation UIImage (Color)  
  8.   
  9. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size  
  10. {  
  11.     CGRect rect = CGRectMake(0, 0, size.width, size.height);  
  12.     UIGraphicsBeginImageContext(rect.size);  
  13.     CGContextRef context = UIGraphicsGetCurrentContext();  
  14.     CGContextSetFillColorWithColor(context,color.CGColor);  
  15.     CGContextFillRect(context, rect);  
  16.     UIImage *img = UIGraphicsGetImageFromCurrentImageContext();  
  17.     UIGraphicsEndImageContext();  
  18.       
  19.     return img;  
  20. }  
  21. @end

以上是关于用色值生成图片的主要内容,如果未能解决你的问题,请参考以下文章