如何创建一个有限的 CIImage?
How can I create a finite CIImage?
CIColorMap
CIFilter
将 CIImage
作为输入。使用另一个 CIFilter
(例如 CILinearGradient
)动态生成该输入图像是有意义的,但是向颜色图过滤器提供过滤器的结果将导致如下错误:
[CIColorMap outputImage] requires the inputGradientImage to be finite
即使梯度的 start/end 点被指定为 CILinearGradient
过滤器的输入,图像本身也不是有限的。如何生成有限的 CIImage 以传递给我的过滤器?
下面是一个示例,说明如何创建固定大小 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"];
CIColorMap
CIFilter
将 CIImage
作为输入。使用另一个 CIFilter
(例如 CILinearGradient
)动态生成该输入图像是有意义的,但是向颜色图过滤器提供过滤器的结果将导致如下错误:
[CIColorMap outputImage] requires the inputGradientImage to be finite
即使梯度的 start/end 点被指定为 CILinearGradient
过滤器的输入,图像本身也不是有限的。如何生成有限的 CIImage 以传递给我的过滤器?
下面是一个示例,说明如何创建固定大小 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"];