Re: Relative pathnames e.g. when initializing NSImages?
Re: Relative pathnames e.g. when initializing NSImages?
- Subject: Re: Relative pathnames e.g. when initializing NSImages?
- From: Andrew Pinski <email@hidden>
- Date: Sat, 11 May 2002 12:08:37 -0400
The current path gets set to / when the app is launched the Finder.
You might what to use this message instead `imageNamed:'
Here is the quote from the docs for that message:
+ (id)imageNamed:(NSString *)name
Returns the NSImage instance associated with name. The returned object
will be one that's been assigned a name with the setName: method
If there's no known NSImage with name, this method tries to create one
by searching for image data in the application's main bundle (see
NSBundle's class description for a description of how the bundle's
contents are searched). If a file contains data for more than one image,
a separate representation is created for each. If an image
representation can't be found for name, no object is created and nil is
returned.
The preferred way to name an image is to ask for a name without the
extension, but to include the extension for a file name.
One particularly useful image is referenced by the string
"NSApplicationIcon". If you supply this string to imageNamed:, the
returned image will be the application's own icon. Icons for other
applications can be obtained through the use of methods declared in the
NSWorkspace class.
The image returned by this method should not be freed, unless it's
certain that no other objects reference it.
See Also: - setName:, - name, - iconForFile: (NSWorkspace), +
imageFileTypes
Thanks,
Andrew Pinski
On Saturday, May 11, 2002, at 10:14 , Nathan Groh wrote:
When using NSImage's initWithContentsOfFile: method, I'm forced to
use an absolute pathname. A standard Unix relative pathname invariably
fails. Is there some special Darwin voodoo regarding relative paths
that I'm in the dark about? I've tried both a relative path from the
application, e.g. @"Graphics/image.tiff" where Graphics is the folder
containing the app's images, and a relative path from the user's home
directory e.g. @"~/Application/Graphics/image.tiff". Both paths fail to
initialize the NSImage successfully, and I'm forced to use a path like
@"/Users/theuser/Application/Graphics/image.tiff". Obviously I'm
missing something. Can someone shed some light on the situation for me?
Fiat lux. : )
Thanks in advance,
--Nathan
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.