On 11 Nov 2014, at 12:18, Uli Kusterer wrote:
Now of course I can just create a hand-drawn selected version, but I
like doing things like that in code. So I’d like to have code that
takes the NSImage and makes it glow like Xcode here:
https://www.dropbox.com/s/by642iw7xosnki7/Screenshot%202014-11-04%2011.40.18.png?dl=0
OK, so that’s not actually a glow, you’re just trying to tint an
image in a different color, it seems? I presume your image is a flat
2D glyph like Xcode’s as well?
You will want to look into the compositing modes that Quartz supports
[…]
This code should draw a monochrome `srcImage` (with alpha) at `dstRect`
in blue:
NSImage* srcImage = …;
NSRect dstRect = …;
// Save graphics state since we’ll install a clipping mask
[NSGraphicsContext saveGraphicsState];
// Setup a mask based on our image
CGImageRef cgImage = [srcImage CGImageForProposedRect:&dstRect
context:[NSGraphicsContext currentContext] hints:nil];
CGContextClipToMask((CGContextRef)[[NSGraphicsContext currentContext]
graphicsPort], dstRect, cgImage);
[[NSColor blueColor] set];
NSRectFillUsingOperation(dstRect, NSCompositeSourceOver);
// Restore graphics state (without the clipping mask)
[NSGraphicsContext restoreGraphicsState];
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com