• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Relative pathnames e.g. when initializing NSImages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Displaying a menu at arbitrary location.
      • From: Gideon King <email@hidden>
References: 
 >Relative pathnames e.g. when initializing NSImages? (From: Nathan Groh <email@hidden>)

  • Prev by Date: my screensaver doesn't let screensaver panel to change the screensaver
  • Next by Date: Re: Minor filesize differences between "info" inspector and NSFileManager on SOME files.
  • Previous by thread: Re: Relative pathnames e.g. when initializing NSImages?
  • Next by thread: Displaying a menu at arbitrary location.
  • Index(es):
    • Date
    • Thread