Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 375691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:31:36+00:00 2026-05-12T14:31:36+00:00

I have a grayscale image which I want to use for drawing Cocoa controls.

  • 0

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 darkest. I want it to be transparent where the source image is white.

Basically, I want to reproduce the behavior of tintColor seen in UINavigationBar on the iPhone.

So far, I have explored several options:

  • Draw the tint color over the grayscale image using SourceOver composition
    -> This requires a non-opaque tint color
    -> The result comes out much darker than desired

  • Use a CIMultiplyCompositing CIFilter to tint the image
    -> I can’t [CIImage drawAtPoint:fromRect:operation:fraction:] to draw only part of the image. The same works fine with NSImage
    -> I get occasional crashes which I cannot make sense of

  • Transform the grayscale image into a mask. I.e. Black should be opaque. White should be transparent. Gray should have intermediate alpha values.
    -> This would seem to be the best solution
    -> Try as I might, I cannot achieve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:31:37+00:00Added an answer on May 12, 2026 at 2:31 pm
    - (NSImage *)imageTintedWithColor:(NSColor *)tint 
    {
        if (tint != nil) {
            NSSize size = [self size];
            NSRect bounds = { NSZeroPoint, size };
            NSImage *tintedImage = [[NSImage alloc] initWithSize:size];
    
            [tintedImage lockFocus];
    
            CIFilter *colorGenerator = [CIFilter filterWithName:@"CIConstantColorGenerator"];
            CIColor *color = [[[CIColor alloc] initWithColor:tint] autorelease];
    
            [colorGenerator setValue:color forKey:@"inputColor"];
    
            CIFilter *monochromeFilter = [CIFilter filterWithName:@"CIColorMonochrome"];
            CIImage *baseImage = [CIImage imageWithData:[self TIFFRepresentation]];
    
            [monochromeFilter setValue:baseImage forKey:@"inputImage"];     
            [monochromeFilter setValue:[CIColor colorWithRed:0.75 green:0.75 blue:0.75] forKey:@"inputColor"];
            [monochromeFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputIntensity"];
    
            CIFilter *compositingFilter = [CIFilter filterWithName:@"CIMultiplyCompositing"];
    
            [compositingFilter setValue:[colorGenerator valueForKey:@"outputImage"] forKey:@"inputImage"];
            [compositingFilter setValue:[monochromeFilter valueForKey:@"outputImage"] forKey:@"inputBackgroundImage"];
    
            CIImage *outputImage = [compositingFilter valueForKey:@"outputImage"];
    
            [outputImage drawAtPoint:NSZeroPoint
                            fromRect:bounds
                           operation:NSCompositeCopy
                            fraction:1.0];
    
            [tintedImage unlockFocus];  
    
            return [tintedImage autorelease];
        }
        else {
            return [[self copy] autorelease];
        }
    }
    
    - (NSImage*)imageCroppedToRect:(NSRect)rect
    {
        NSPoint point = { -rect.origin.x, -rect.origin.y };
        NSImage *croppedImage = [[NSImage alloc] initWithSize:rect.size];
    
        [croppedImage lockFocus];
        {
            [self compositeToPoint:point operation:NSCompositeCopy];
        }
        [croppedImage unlockFocus];
    
        return [croppedImage autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a texture which has only 1 channel as it's a grayscale image.
I have a 16 bit grayscale image that I want to display using WPF
I have a greyscale image which has pixel values ranging from 1.000 to 1.003.
I have a greyscale image which was created from a RGB image using farmula:
I have an IMG tag with a grayscale image. I hooked up a Hover()
Imagine you have two images A and B, and a third grayscale image T.
I need a way to have a gray scale image in an ImageView and
I have a grayscale image that needs to be painted with values from a
Is it possible to use the FromStream method of System.Drawing.Image without having to keep
I have a grayscale image from a photograph. I've determined that certain parts of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.