5

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...)

Community
  • 1
  • 1
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223

1 Answers1

9

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];
Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • 1
    Good. NSCompositingOperationSourceOver is now used instead of the deprecated NSCompositeSourceOver. – wcochran Mar 01 '18 at 18:47