2012-02-03 25 views
0

我有一个UIImage,其中包含一个图案,图像的其余部分是透明的。这是一个PNG文件,模式只有一种颜色。我已经创建了一个表格,用户可以从中选取一种颜色(一种UIColor),并且我想将图案的颜色更改为用户挑选的颜色。我知道如何改变图像中像素的颜色,但是有什么方法可以改变整个图案的颜色,还是必须逐个更改每个像素?如何更改整个图像的颜色

回答

0

我遇到了另一个话题在这里,我不记得这是什么所谓!! :(但在情况下,如果你看图像色彩处理,你会发现它:)

1

进入图像和您想要将其更改为以下方法的颜色。将基于轮廓返回给您一个新鲜的彩色图像。

-(UIImage *)returnImage:(UIImage *)image coloured:(UIColor *)colour { 

UIGraphicsBeginImageContext(image.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height); 

CGContextTranslateCTM(context, 0, image.size.height); 
CGContextScaleCTM(context, 1.0, -1.0); 

CGContextClipToMask(context, rect, image.CGImage); 
CGContextAddRect(context, rect); 
CGContextDrawPath(context,kCGPathFill); 

CGContextSetFillColorWithColor(context, colour.CGColor); 
CGContextFillRect(context, rect); 

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return newImage; 

}