Re: NSImage glowing
Re: NSImage glowing
- Subject: Re: NSImage glowing
- From: Lee Ann Rucker <email@hidden>
- Date: Tue, 04 Nov 2014 19:48:10 +0000
- Thread-topic: NSImage glowing
If you want the same blue highlight that NSButton applies to template images, you can get the NSButtonCell to draw it into a graphics context and get an image that way - I answered this when you asked about buttons specifically back in June. (My bug requesting an NSImage method to do that is still open and presumably unloved) Once you've got your buttonCell configured, do this:
NSRect bounds = NSZeroRect;
bounds.size = [template size];
NSBitmapImageRep *bmpImageRep =
[NSBitmapImageRep imageRepWithSize:bounds.size scale:scale]; // Utility wrapper around imageRepWith32bitBuffer
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext *bitmapContext =
[NSGraphicsContext graphicsContextWithBitmapImageRep:bmpImageRep];
[NSGraphicsContext setCurrentContext:bitmapContext];
[buttonCell drawImage:template withFrame:bounds inView:nil];
[NSGraphicsContext restoreGraphicsState];
return bmpImageRep;
On Nov 4, 2014, at 10:41 AM, Alex Kac <email@hidden> wrote:
> I have an NSImage that looks like in a mini-toolbar - kind of like Xcode.
>
> 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://urldefense.proofpoint.com/v2/url?u=https-3A__www.dropbox.com_s_by642iw7xosnki7_Screenshot-25202014-2D11-2D04-252011.40.18.png-3Fdl-3D0&d=AAIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=ie7S-J__EKnfyVOBV7-jV2rZ--p47O6vkyTklpDM3h4&m=lUNK2PEwQXtoqjBGMWU6Y3iSwSvLFO0mx-2wI6kiSNg&s=PSrnj94BQRWKM8dFv5gi7Tz3a3NH1_5gmiUvJHsFfP4&e=
>
> I’ve Googled this and I see a bunch of stuff, that I can’t get working at all. Most articles were for iOS and some repsonders even said “if I was using an NSImage, this would be easy - but for iOS you do…”.
>
> So… can anyone point me to the right place?
>
> _______________________________________________
>
> 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:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.apple.com_mailman_options_cocoa-2Ddev_lrucker-2540vmware.com&d=AAIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=ie7S-J__EKnfyVOBV7-jV2rZ--p47O6vkyTklpDM3h4&m=lUNK2PEwQXtoqjBGMWU6Y3iSwSvLFO0mx-2wI6kiSNg&s=QsN7f2Wy2w3J4nIWtViq9WfFRo-Fwf46hQqveR8coB0&e=
>
> This email sent to email@hidden
_______________________________________________
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