0

我有一张黑白图像,我想在objective-c中改变蓝色的黑色和黄色的白色(例如)。

我怎么能这样做?

谢谢

4

1 回答 1

4

您可以使用 Core Image 来执行此操作。

UIImage *bwImage = ... // Get your image from somewhere
CGImageRef bwCGImage = bwImage.CGImage;
CIImage *bwCIImage = [CIImage imageWithCGImage:bwCGImage];

CIFilter *filter = [CIFilter filterWithName:@"CIHueAdjust"];

// Change the float value here to change the hue
[filter setValue:[NSNumber numberWithFloat:0.5] forKey: @"inputAngle"]; 

// input black and white image
[filter setValue:bwCIImage forKey:kCIInputImageKey];

// get output from filter
CIImage *hueImage = [filter valueForKey:kCIOutputImageKey];

CIContext *context = [CIContext contextWithOptions:nil];

CGImageRef cgImage = [context createCGImage:hueImage
                                 fromRect:[hueImage extent]];

UIImage *coloredImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);

有关更多信息,请参阅文档:核心图像过滤器参考

于 2013-05-21T07:42:36.933 回答