3

i tried using the CGContextSetRGBStrokeColor before now i want to use other way to do the color change.

I am using now an image as a stroke and i want to change it's color with the use of those CGBlendModes.

How will i able to control the Hue and Saturation using kCGBlendModeHue and kCGBlendModeSaturation? i'll use it to change the stroke color on button click.

2 Answers 2

1

You will want to do something like this:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, rect, image.CGImage);
CGContextSetBlendMode(context, kCGBlendModeHue);
CGContextDrawImage(context, rect, overlay.CGImage);
0
1

Thanks to @Patrick Tescher's answer, this works:

- (void) changeToHue:(float)hue saturation:(float)saturation {
    UIGraphicsBeginImageContext(self.bounds.size);
    CGContextRef context = UIGraphicsGetCurrentContext();    
    UIView *hueBlend = [[UIView alloc] initWithFrame:self.bounds];
    hueBlend.backgroundColor = [UIColor colorWithHue:hue saturation:saturation brightness:1 alpha:1];
    CGContextDrawImage(context, self.bounds, self.image.CGImage);
    CGContextSetBlendMode(context, kCGBlendModeHue);
    [hueBlend.layer renderInContext:context];
    self.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.