• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImage glowing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage glowing


  • Subject: Re: NSImage glowing
  • From: Allan Odgaard <email@hidden>
  • Date: Tue, 11 Nov 2014 12:40:32 +0100

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 2014-11-04 11.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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >NSImage glowing (From: Alex Kac <email@hidden>)
 >Re: NSImage glowing (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: NSImage glowing
  • Next by Date: Re: updating NSTextField before spinner animates
  • Previous by thread: Re: NSImage glowing
  • Next by thread: dispatch_source does not work
  • Index(es):
    • Date
    • Thread