Replace color in uiimage with another color

Is there an API that I could use (possibly in coreimage) to change all the pixels of a certain color to a different color? I think I can understand how to do it manually, iterating through each pixel of the image, but I hope there is a more elegant (and higher level of performance) way to do this.

+4
source share
2 answers

your image color is replaced with red below the code

Your image source code:

UIImageView *image1 =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[image1 setImage:[UIImage imageNamed:@"Lock.png"]];
[self.view addSubview:image1];

Color Code Rad Color

CGRect rect = CGRectMake(0, 0, image1.frame.size.width, image1.frame.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, [UIImage imageNamed:@"Lock.png"].CGImage);
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage
                                            scale:1.0 orientation: UIImageOrientationDownMirrored];

image1.image = flippedImage;

Source image

enter image description here

Color image

enter image description here

+3
source

CIColorCube Core Image. , , .

0

Source: https://habr.com/ru/post/1533853/


All Articles