2

我尝试生成 CIGaussianGradient 但我在控制台中得到了休闲输出

012-08-03 16:45:10.423 OGL[2882:303] *** Assertion failure in -[NSBitmapImageRep initWithCIImage:], /SourceCache/AppKit/AppKit-1187/AppKit.subproj/NSBitmapImageRep.m:1531
2012-08-03 16:45:10.425 OGL[2882:303] An uncaught exception was raised
2012-08-03 16:45:10.427 OGL[2882:303] <CIImage: 0x400353620> {
    FEPromise: 0x4007106e0 extent: infinite; filter CIGaussianGradient: 0x4001ecde0; kernel gaussianDot; center [150 150] color0 <CGColor 0x40021b6e0> [<CGColorSpace 0x400417ca0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Generic RGB Profile)] ( 1 1 1 0 ) color1 <CGColor 0x400236180> [<CGColorSpace 0x400417ca0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Generic RGB Profile)] ( 0 0 0 1 ) radius_recip 0.00333333
} parameter to -initWithCIImage: is not of finite extent

虽然我的应用代码如下所示:

CIFilter *F = [CIFilter filterWithName:@"CIGaussianGradient"];
[F setDefaults];
[F setValue:[CIColor colorWithRed:1 green:1 blue:1 alpha:0] forKey:@"inputColor0"];
[F setValue:[CIColor colorWithRed:0 green:0 blue:0 alpha:1] forKey:@"inputColor1"];
CIImage *Fimg = [F valueForKey:@"outputImage"];
NSBitmapImageRep *FBitmap = [[NSBitmapImageRep alloc] initWithCIImage:Fimg];

我的错误在哪里?

4

1 回答 1

3

必须将无限平面的一部分裁剪为图像。请参阅:Core Image 使用 CIGaussianGradient 滤镜的示例

在下面的示例中,创建了一个 600 x 600 的图像。

例子:

// create a CIImage and apply the filter
CIImage *theCIImage = [[CIImage alloc] init];
theCIImage = [CIFilter filterWithName:@"CIGaussianGradient" keysAndValues:@"inputCenter", centerVector, @"inputColor0", color0, @"inputColor1", color1, @"inputRadius", radius, nil].outputImage;

// crop the image using CICrop
CGRect rect = CGRectMake(0.0, 0.0, 600.0, 600.0);
theCIImage = [CIFilter filterWithName:@"CICrop" keysAndValues:kCIInputImageKey, theCIImage, @"inputRectangle", rect, nil].outputImage;

NSBitmapImageRep *FBitmap = [[NSBitmapImageRep alloc] initWithCIImage:theCIImage];
于 2012-11-16T03:05:07.883 回答