Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How best to cache/preload an NSImage?



Currently, I am doing something like this:

// typed in mail, not real code
NSImage *sourceImage, *cachedImage;
sourceImage = [NSImage initWithFileContents:myPath];
cachedImage = [[NSImage alloc] initWithSize:newSize];
[cachedImage lockFocus];
[sourceImage drawInRect:newRect fromRect:oldRect ...];
[cachedImage unlockfocus];
// cachedImage now contains one NSCachedImageRep

Problem is, when my custom NSView draws this image for the first time,
there's a small but noticeable lag. The second time (after I've
switched to another image, then back), it's instantaneous. I suspect
this has something to do with NSImage buffering to its offscreen
window, but I don't know how to force it do that without drawing on a
real window.

Any pointers would be appreciated, or suggestions on other ways to
solve approach this task...

-Dominic
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.