2012-03-31 108 views
3

我不确定这是否是正确的要求...但我想要的基本上是“粉饰”一个NSImage,或者减少其不透明度 ...(Finder中的一个“非活动”图标?类似的东西)NSImage +透明度?

什么是最简单的方法来实现这一目标?

我试过这里(NSImage transparency)所示的例子,但它绝对没有工作对我来说...

(顺便说一句,在NSImage中会在ImageAndTextCell,如果有什么差别。 ..)

+0

你试过用alpha合成? – 2012-04-01 00:41:01

回答

6

所有你需要做的就是绘制一个alpha值小于1.0的图像。在你的实现ImageAndTextCell,只是使用类似这样的-drawWithFrame:inView:方法:

[image drawInRect:someRect 
     fromRect:NSZeroRect 
     operation:NSCompositeSourceOver //this draws the image using the alpha mask 
     fraction:0.5]; 
+0

谢谢!它正在... :-) – 2012-04-02 19:32:44

+0

好。现在使用NSCompositingOperationSourceOver代替已弃用的NSCompositeSourceOver。 – wcochran 2018-03-01 18:47:58