Tinting a grayscale NSImage (or CIImage)

后端 未结 8 1910
轮回少年
轮回少年 2021-01-30 09:02

I have a grayscale image which I want to use for drawing Cocoa controls. The image has various levels of gray. Where it is darkest, I want it to draw a specified tint color dark

相关标签:
8条回答
  • 2021-01-30 10:06

    The above solution didn't work for me. But this much easier solution works great for me

    - (NSImage *)imageTintedWithColor:(NSColor *)tint
    {
        NSImage *image = [self copy];
        if (tint) {
            [image lockFocus];
            [tint set];
            NSRect imageRect = {NSZeroPoint, [image size]};
            NSRectFillUsingOperation(imageRect, NSCompositeSourceIn);
            [image unlockFocus];
        }
        return image;
    }
    
    0 讨论(0)
  • 2021-01-30 10:06

    For a more fine grained, you can use a polynomial color approach, using the approach that I suggested in the following: How can I display the spinning NSProgressIndicator in a different color?

    0 讨论(0)
提交回复
热议问题