Search code examples
objective-ccocoatransparencyopacitynsimage

NSImage + Transparency?


I'm not sure whether it's the right thing to ask for... but what I want is basically "whitewashing" an NSImage, or reducing its opacity... (sort of an "inactive" icon in Finder? something like that)

What's the easiest way to achieve this?

I've tried the example shown here (NSImage transparency), but it definitely did NOT work for me...

(Btw, the NSImage will be in an ImageAndTextCell, if that makes any difference...)


Solution

  • All you need to do is draw the image with an alpha of less than 1.0. In your implementation of ImageAndTextCell, just use something like this in the -drawWithFrame:inView: method:

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