Skip navigation.
 
mlRe: NSImage scaling and ugliness
FROM : Matt Neuburg
DATE : Fri Jul 14 22:57:15 2006

On Thu, 13 Jul 2006 12:55:17 -0700, I <<email_removed>> 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_removed>, <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>

Related mailsAuthorDate
mlNSImage scaling and ugliness Stephen F. Booth Jul 10, 20:42
mlRe: NSImage scaling and ugliness Christian Walther Jul 10, 22:05
mlRe: NSImage scaling and ugliness Matt Neuburg Jul 12, 05:11
mlRe: NSImage scaling and ugliness Matt Neuburg Jul 13, 21:55
mlRe: NSImage scaling and ugliness Matt Neuburg Jul 14, 22:57