Re: Error initializing an NSImage
Re: Error initializing an NSImage
- Subject: Re: Error initializing an NSImage
- From: John Timmer <email@hidden>
- Date: Sat, 01 Mar 2003 09:39:12 -0500
If the image is in your resources folder, the following code works (and is
quite convenient):
image = [NSImage imageNamed:@"newFile "];
Cheers,
John
>
I am trying to initialize an image, that's all I'm doing.
>
But for some reason it fails, my NSAssert saying that filePath is nil.
>
The bundle printed in NSLog as "NSBundle
>
</Users/hisaokin/Desktop/MyApp/build/MyApp.app> (loaded)"
>
newFile is valid. It's the name of the file without the extension, and
>
it exists in a folder called Resources in my project folder. The
>
extension is ".tiff". I tried with many TIFF images, same result. How
>
could the filePath be nil? it's really puzzling me.
>
>
Here's the code:
>
>
NSBundle * mainBundle = [NSBundle mainBundle];
>
NSString * filePath = [mainBundle pathForResource:newFile
>
ofType:@"tiff"];
>
NSImage * image = [[[NSImage alloc]
>
initWithContentsOfFile:[filePath stringByExpandingTildeInPath]]
>
autorelease];
>
>
>
Rather simple..
>
>
Any help appreciated!
>
>
>
Thanks,
>
>
>
-yuki
>
_______________________________________________
>
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.
_______________________________________________
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.