Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 如何更改整个图像的颜色_Image Processing_Uiimage - Fatal编程技术网

Image processing 如何更改整个图像的颜色

Image processing 如何更改整个图像的颜色,image-processing,uiimage,Image Processing,Uiimage,我有一张中间有图案的UIImage,图像的其余部分是透明的。这是一个png文件,图案只有一种颜色。我已经创建了一个表格,用户可以从中选择颜色(UIColor),我想将图案的颜色更改为用户选择的颜色。我知道如何更改图像中某个像素的颜色,但是有没有办法更改整个图案的颜色,或者我必须逐个更改每个像素?我在这里遇到了另一个主题,我不记得它叫什么了!!:(但在这种情况下,如果您查找图像颜色处理,您会发现:)将图像和要更改的颜色输入到下面的方法中。将返回一个基于轮廓的新彩色图像 -(UIImage *)re

我有一张中间有图案的UIImage,图像的其余部分是透明的。这是一个png文件,图案只有一种颜色。我已经创建了一个表格,用户可以从中选择颜色(UIColor),我想将图案的颜色更改为用户选择的颜色。我知道如何更改图像中某个像素的颜色,但是有没有办法更改整个图案的颜色,或者我必须逐个更改每个像素?

我在这里遇到了另一个主题,我不记得它叫什么了!!:(但在这种情况下,如果您查找图像颜色处理,您会发现:)

将图像和要更改的颜色输入到下面的方法中。将返回一个基于轮廓的新彩色图像

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

}