Reputation: 1040
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.
Upvotes: 3
Views: 1433
Reputation: 69787
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();
}
Upvotes: 1
Reputation: 3447
You will want to do something like this:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, rect, image.CGImage);
CGContextSetBlendMode(context, kCGBlendModeHue);
CGContextDrawImage(context, rect, overlay.CGImage);
Upvotes: 1