我必须生成一个图像 < a href=" "http:// developmenter.apple.com/library/mac/#document/Graphicsimage/Reference/CoreImageFilterReference/Reference/Reference/ reference.html#//apple_ref/doc/filter/ci/CIRadialGradient" rel="nofollown norefererr", 和这里在CIRadialGradient苹果文档中找到的 :
"https://i.sstatic.net/UoH89.gif" alt="CIRadialGradient"/> https://i.sstatic.net/UoH89.gif" alt="CIRadial Gradient"/>
我尝试了很多方法,最后却说:
+(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;
}
但我只能得到一个空虚的图像。
帮帮我吧
谢谢 谢谢
菲利克斯