Re: NSImage scaling and ugliness
Re: NSImage scaling and ugliness
- Subject: Re: NSImage scaling and ugliness
- From: Matt Neuburg <email@hidden>
- Date: Fri, 14 Jul 2006 13:57:15 -0700
- Thread-topic: NSImage scaling and ugliness
On Thu, 13 Jul 2006 12:55:17 -0700, I <email@hidden> said:
>Here is some code that I'm now using in my app:
>
> icon = [[NSWorkspace sharedWorkspace] iconForFile:(NSString*)path];
> NSSize tinySize = NSMakeSize(16.0, 16.0);
> [icon setSize: tinySize];
> // now check to see whether that actually worked
> NSEnumerator* e = [[icon representations] objectEnumerator];
> NSImageRep* rep;
> BOOL has16 = NO;
> while ((rep = [e nextObject])) {
> if (NSEqualSizes([rep size], tinySize)) {
> has16 = YES; break;
> }
> }
> if (!has16) {
> NSImage* newIcon = [[NSImage alloc] initWithSize:NSMakeSize(16.0,
>16.0)];
> [newIcon lockFocus];
> [[NSGraphicsContext currentContext]
>setImageInterpolation:NSImageInterpolationHigh];
> [icon drawInRect:NSMakeRect(0,0,16,16) fromRect:NSMakeRect(0,0, [icon
>size].width, [icon size].height) operation:NSCompositeCopy fraction:1.0];
> [newIcon unlockFocus];
> icon = [newIcon autorelease];
> }
Change "now" to "not". It turns out that merely asking for [icon
representations] is insanely expensive (time-consuming). So the real upshot
is that I'd rather take the chance of having a few ugly icons than have my
window take 20 times as long to display.
So *why* is calling -[NSImage representations] expensive? Does it have
something to do with caching?
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden