- (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();
}
4 comments:
Hi there,
i tried your method but i keep getting the error: property 'bounds' not found on object of type 'ViewController *'
Is there some header file i need for this to work? I really love to get this working.
Sorry, missed your comment for some reason. If you are in a UIView subclass then you can access self.bounds.
try self.view.bounds . . worked for me :)
I have a uiimage in which some middle part is transparent , this method also applying hue on that part , what should i do to stop that thing ?
Otherwise nice piece of code , very handy .Thanx.
Post a Comment