改变iOS图片色调

3

我想使用滑块更改图像的色调。我的做法是:

float slideValue =  sldHueChange.value;
beginImage= [CIImage imageWithCGImage:imgBorder.image.CGImage];
context = [CIContext contextWithOptions:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:kCIContextUseSoftwareRenderer]];
filter= [CIFilter filterWithName:@"CIHueAdjust"];
[filter setValue:beginImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:slideValue] forKey:@"inputAngle" ];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg =[context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[imgBorder setImage:newImg];
CGImageRelease(cgimg);

它可以工作,但不够流畅。我想要让图像色调变化更加平滑。如果你有制作流畅的色调变化器的想法,请分享一下。我非常需要它。提前谢谢。

2个回答

1

Now what I'm doing is:

CGRect rect = CGRectMake(0, 0, selectedBorderForChangingHue.size.width, selectedBorderForChangingHue.size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context1 = UIGraphicsGetCurrentContext();
CGContextClipToMask(context1, rect, selectedBorderForChangingHue.CGImage);
CGContextSetFillColorWithColor(context1, [[UIColor colorWithHue:sldHueChange.value/255.0f saturation:1.0f brightness:1.0f alpha:1.0f] CGColor]);
CGContextFillRect(context1, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored];
imgBorder.image = flippedImage;

对我来说它运行良好,而且非常流畅。


你是怎么发现 "selectedBorderForChangingHue" 的? - Shailesh

1
我建议您使用 Brad 的惊人 GPUImage,它有很多滤镜,或者您可以尝试使用 GPU 渲染 CIContext,在选项字典中将布尔值更改为 NO 以创建 CIContext。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接