How to programmatically change the hue of UIImage?

后端 未结 5 859
南笙
南笙 2020-12-01 01:26

I am very new to the image processing. I have to implement hue effect in my iPhone application project. Therefore, I need to change the hue of UIImage. Please p

5条回答
  •  萌比男神i
    2020-12-01 01:46

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

提交回复
热议问题