注意:这是在OSX NOT iOs ......
NSColor有一个简洁的帮助方法叫做" colorWithPatternImage"这使您可以将任何图像视为"填充"例如,一个NSBezierPath。
我想用它来创建多个重叠的正方形,其中包含我可以改变其不透明度的图像。
麻烦如下:
// ok - solid white
NSColor *fillColor = [NSColor whiteColor];
// ok - same as above
fillColor = [[NSColor whiteColor] colorWithAlphaComponent:1.0];
// ok - alpha of 50% (light grey)
fillColor = [[NSColor whiteColor] colorWithAlphaComponent:0.5];
// ok - fills with content of NSImage backgroundImage
fillColor = [NSColor colorWithPatternImage:backgroundImage];
// ok - same as above
fillColor = [[NSColor colorWithPatternImage:backgroundImage] colorWithAlphaComponent:1.0];
// FAILS! - any value less than 1.0 acts like alpha is 0.0
fillColor = [[NSColor colorWithPatternImage:backgroundImage] colorWithAlphaComponent:0.9];
有关如何实现这一目标的任何想法?我确实尝试首先使用alpha重新绘制NSImage,然后将其用作" patternImage。"虽然这确实正确地将alpha应用于图像本身,但它对路径没有任何作用,因此您最终会得到一个"变暗的"但不透明的图像。
我错过了什么?