CIColorMap
CIFilter
将CIImage
作为输入。使用另一个CIFilter
(例如CILinearGradient
)动态生成输入图像是有意义的,但是向颜色映射过滤器提供过滤器的结果将导致以下错误,如下所示:
[CIColorMap outputImage]要求inputGradientImage是有限的
即使将渐变的起点/终点指定为CILinearGradient
滤镜的输入,图像本身也不是有限的。如何生成有限的CIImage以传递给我的过滤器?
答案 0 :(得分:1)
以下是如何创建固定尺寸CIImage
以用作另一个CIFilter
的输入的示例:
CGFloat gradientSize = 100.f;
CIFilter *gradientFilter = [CIFilter filterWithName:@"CISmoothLinearGradient"];
[gradientFilter setValue:[CIVector vectorWithX:0 Y:0] forKey:@"inputPoint0"];
[gradientFilter setValue:[CIVector vectorWithX:gradientSize Y:0] forKey:@"inputPoint1"];
[gradientFilter setValue:[CIColor colorWithCGColor:[[UIColor cyanColor] CGColor]] forKey:@"inputColor0"];
[gradientFilter setValue:[CIColor colorWithCGColor:[[UIColor magentaColor] CGColor]] forKey:@"inputColor1"];
CIImage *gradientImage = [[gradientFilter outputImage] imageByCroppingToRect:CGRectMake(0, 0, gradientSize, 1)];
// Other filter to receive cropped gradientImage
CIFilter *gradientMapFilter = [CIFilter filterWithName:@"CIColorMap"];
[gradientMapFilter setValue:gradientImage forKey:@"inputGradientImage"];