Created
January 2, 2014 21:32
-
-
Save barchard/8227332 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usually, initialize an NSImage with a black and white Vector image (pdf) | |
- (NSImage *)cdsMaskedWithColor:(NSColor *)color | |
{ | |
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height); | |
NSImage *result = [[NSImage alloc] initWithSize:self.size]; | |
[result lockFocusFlipped:self.isFlipped]; | |
NSGraphicsContext *context = [NSGraphicsContext currentContext]; | |
CGContextRef c = (CGContextRef)[context graphicsPort]; | |
[self drawInRect:NSRectFromCGRect(rect)]; | |
CGContextSetFillColorWithColor(c, [color CGColor]); | |
CGContextSetBlendMode(c, kCGBlendModeSourceAtop); | |
CGContextFillRect(c, rect); | |
[result unlockFocus]; | |
return [result autorelease]; | |
} | |
+ (NSImage *)cdsMaskedImageNamed:(NSString *)name color:(NSColor *)color | |
{ | |
NSImage *image = [NSImage imageNamed:name]; | |
return [image cdsMaskedWithColor:color]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment