如何在iPhone sdk中获取彩色图像 [英] How to get a color image in iPhone sdk
本文介绍了如何在iPhone sdk中获取彩色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要如下内容
UIImage *solid = [UIImage imageWithColor:[UIColor darkGrayColor]];
创建关于某种颜色的图像。
to create an image with respect to some color.
如何在iPhone sdk中执行此操作。
how to do it in iPhone sdk.
推荐答案
您可以将颜色绘制到CGContext中,然后从中捕获图像:
You can draw the color into a CGContext and then capture an image from it:
- (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
//Create a context of the appropriate size
UIGraphicsBeginImageContext(size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//Build a rect of appropriate size at origin 0,0
CGRect fillRect = CGRectMake(0,0,size.width,size.height);
//Set the fill color
CGContextSetFillColorWithColor(currentContext, color.CGColor);
//Fill the color
CGContextFillRect(currentContext, fillRect);
//Snap the picture and close the context
UIImage *retval = UIGraphicsGetImageFromCurrentImageContext(void);
UIGraphicsEndImageContext();
return retval;
}
这篇关于如何在iPhone sdk中获取彩色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文