我必须在此处找到 CIRadialGradient 的 Apples Doc 中生成的图像:
我尝试了很多方法并以:
+(NSImage*)radialGradientWithR0:(float)r0 r1:(float)r1 c0:(NSColor*)c0 c1:(NSColor*)c1 imageDimensionPx:(int)imageDimension
{
CIColor* cc0 = [[CIColor alloc]initWithColor:c0];
CIColor* cc1 = [[CIColor alloc]initWithColor:c1];
CIVector* civ = [CIVector vectorWithX:imageDimension/2 Y:imageDimension/2];
CIFilter* filter = [CIFilter filterWithName:@"CIRadialGradient"];
[filter setDefaults];
[filter setValue:civ forKey:@"inputCenter"];
[filter setValue:[NSNumber numberWithFloat:r0] forKey:@"inputRadius0"];
[filter setValue:[NSNumber numberWithFloat:r0] forKey:@"inputRadius1"];
[filter setValue:cc0 forKey:@"inputColor0"];
[filter setValue:cc1 forKey:@"inputColor1"];
CIImage* outputImage = [filter valueForKey:@"outputImage"];
NSRect outputImageRect = NSRectFromCGRect([outputImage extent]);
NSImage* blurredImage = [[NSImage alloc]
initWithSize:NSMakeSize(imageDimension, imageDimension)];
[blurredImage lockFocus];
[blurredImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0, 0, imageDimension, imageDimension) operation:NSCompositeSourceOver fraction:1.0];
[blurredImage unlockFocus];
return blurredImage;
}
但我能得到的只是一个空图像。
请帮我。
谢谢
菲利克斯