2011-11-28 33 views
3

我想在使用CGContextSetRGBStrokeColor之前現在我想用其他方式來做顏色更改。目標C:如何使用kCGBlendModeHue和kCGBlendModeSaturation?

我現在使用一個圖像作爲中風,我想改變它的顏色與使用這些CGBlendModes。

如何使用kCGBlendModeHue和kCGBlendModeSaturation控制色調和飽和度?我會用它來改變點擊按鈕時的筆觸顏色。

回答

1

你會想要做這樣的事情:

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

謝謝,我要再下面你的答案。 –

1

由於@Patrick Tescher的答案,這個工程:

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