【发布时间】:2014-07-25 18:53:16
【问题描述】:
我目前正在使用以下代码进行色调更改:
CGSize imageSize = [imageView.image size];
CGRect imageExtent = CGRectMake(0,0,imageSize.width,imageSize.height);
// Create a context containing the image.
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
[imageView.image drawAtPoint:CGPointMake(0, 0)];
// Draw the hue on top of the image.
CGContextSetBlendMode(context, kCGBlendModeHue);
[color set];
UIBezierPath *imagePath = [UIBezierPath bezierPathWithRect:imageExtent];
[imagePath fill];
// Retrieve the new image.
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
imageView.image= result;
UIGraphicsEndImageContext();
此代码运行良好,唯一的问题是它还设置了透明部分的颜色。我可以避免将色调应用到 UIImage 的透明区域吗?
附上以下两张图片供参考:
提前致谢?
输出
【问题讨论】:
标签: ios objective-c uiimage hue