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: Nathan Groh <email@hidden>
- Date: Sat, 11 May 2002 07:50:49 -0700
Thanks, Matt and ssudre. That explains it. : )
Could someone point me to a tutorial (or at least a source of
information) on embedding images (etc.) into bundles? I really should
learn how to do that one of these days, but I'm not even sure where to
start looking. : )
Thanks again.
--Nathan
On Saturday, May 11, 2002, at 07:37 AM, email@hidden wrote:
>
>
On samedi, mai 11, 2002, at 04: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. : )
>
>
1 quick suggestion:
>
>
Use [@"~/Application/Graphics/image.tiff" stringByExpandingTildeInPath]
>
>
Another suggestion:
>
>
Use the App bundle to store your images, it will allow you to use
>
[NSImage imageNamed:];
On Saturday, May 11, 2002, at 07:37 AM, Matt Gemmell wrote:
NSString has a method -stringByExpandingTildeInPath; use it with a
relative path (from the user's home directory), and you'll get a full
path which you can use to init your NSImage. So, this:
[@"~/Pictures/blah.gif" stringByExpandingTildeInPath]
would give this:
@"/Users/username/Pictures/blah.gif"
Take a look at the NSString documentation in the Foundation reference
for more info on the path-related methods (there are several more useful
ones in there too, including -stringByStandardizingPath).
Best,
-Matt
_______________________________________________
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.