我使用CIColorMonochromeFilter
调整为白色,创建了我认为应该是合适的灰度CIFilter。这看起来非常灰度,但我不是专家,所以我只是想知道这是否是灰度滤镜的精确实现。
我没有编写代码来转储和测试像素,但是根据已经是RBG的图像格式,我很好奇输出图像的格式。例如,我如何知道每个像素是一个组件还是三个组件?
我知道CIImage只是图像的配方,我必须使用CGImageRef最终渲染。我只是不明白我应该期待数据的像素格式。
CIFilter * monoChromeFilter = [CIFilter filterWithName:kCIColorMonochromeFilterName];
[monoChromeFilter setValue:self.inputImage forKey:kCIInputImageKey];
CIColor * white = [CIColor colorWithRed:1.0 green:1.0 blue:1.0];
[monoChromeFilter setValue:white forKey:kCIInputColorKey];
答案 0 :(得分:2)
我希望这对你有帮助(它很快。)
static func convertToBlackAndWhite(image:UIImage) -> UIImage?
{
//first do color controls
let ciImage = CIImage(image:image)
let filter = CIFilter(name: "CIColorControls")
filter.setValue(ciImage, forKey: kCIInputImageKey)
filter.setValue(0.0, forKey: kCIInputBrightnessKey)
filter.setValue(0.0, forKey: kCIInputSaturationKey)
filter.setValue(1.1, forKey: kCIInputContrastKey)
let intermediateImage = filter.outputImage
let filter1 = CIFilter(name:"CIExposureAdjust")
filter1.setValue(intermediateImage, forKey: kCIInputImageKey)
filter1.setValue(0.7, forKey: kCIInputEVKey)
let output = filter1.outputImage
let context = CIContext(options: nil)
let cgImage = context.createCGImage(output, fromRect: output.extent())
return UIImage(CGImage: cgImage, scale: image.scale, orientation: image.imageOrientation)
}