FROM : David Spooner
DATE : Fri Jan 11 22:08:08 2008
I don't know about extending the search list, but you can use
NSBundle's -pathForImageResource: to implement
+ (NSImage *) imageNamed:(NSString *)name fromBundle:(NSBundle *)bundle
{
NSString *path = [bundle pathForImageResource:name];
return path != nil ? [[[NSImage alloc]
initWithContentsOfFile:path] autorelease] : nil;
}
-dave
On 11-Jan-08, at 1:10 PM, glenn andreas wrote:
> NSImage's +imageNamed: is documented as searching the named images
> cache, the apps main bundle, and then the AppKit framework bundle.
> Unfortunately, I've got code in a private framework that wants to
> get the image stored that framework (which isn't thus searched).
>
> Is there some way to add a framework to this search path? (Which
> would be best, because it will allow any object, such as a button,
> that has an image name to automatically work correctly) Or at least
> a way to explicitly pass a bundle to search (via a hypothetical
> +imageNamed:fromBundle:). The fall back, of course, is to get all
> the possible file extensions from NSImage and manually try each and
> every one of them, but I'd rather not have to duplicate this logic
> (plus this fails to support the generic button using a named image
> that resides in the private framework)...
>
> I suppose I could also, at startup, go through all the images in the
> framework, load them, and then do a "setName:" to get them in the
> cache (but this seems like it could impact program launch times)
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> wicked fun!
> quadrium2 | build, mutate, evolve, animate | images, textures,
> fractals, art
DATE : Fri Jan 11 22:08:08 2008
I don't know about extending the search list, but you can use
NSBundle's -pathForImageResource: to implement
+ (NSImage *) imageNamed:(NSString *)name fromBundle:(NSBundle *)bundle
{
NSString *path = [bundle pathForImageResource:name];
return path != nil ? [[[NSImage alloc]
initWithContentsOfFile:path] autorelease] : nil;
}
-dave
On 11-Jan-08, at 1:10 PM, glenn andreas wrote:
> NSImage's +imageNamed: is documented as searching the named images
> cache, the apps main bundle, and then the AppKit framework bundle.
> Unfortunately, I've got code in a private framework that wants to
> get the image stored that framework (which isn't thus searched).
>
> Is there some way to add a framework to this search path? (Which
> would be best, because it will allow any object, such as a button,
> that has an image name to automatically work correctly) Or at least
> a way to explicitly pass a bundle to search (via a hypothetical
> +imageNamed:fromBundle:). The fall back, of course, is to get all
> the possible file extensions from NSImage and manually try each and
> every one of them, but I'd rather not have to duplicate this logic
> (plus this fails to support the generic button using a named image
> that resides in the private framework)...
>
> I suppose I could also, at startup, go through all the images in the
> framework, load them, and then do a "setName:" to get them in the
> cache (but this seems like it could impact program launch times)
>
> Glenn Andreas <email_removed>
> <http://www.gandreas.com/> wicked fun!
> quadrium2 | build, mutate, evolve, animate | images, textures,
> fractals, art
| Related mails | Author | Date |
|---|---|---|
| glenn andreas | Jan 11, 21:10 | |
| David Spooner | Jan 11, 22:08 | |
| Ricky Sharp | Jan 11, 22:34 | |
| glenn andreas | Jan 11, 23:12 |






Cocoa mail archive

