Reputation: 3534
With the following code:
NSString *imageString = [[NSBundle mainBundle] pathForResource:@"logo64x64" ofType:@"png"];
NSImage *testImage = [[NSImage imageNamed:@"logo64X64"] retain];
NSImage *testImage2 = [[NSImage alloc] initWithContentsOfFile:imageString];
testImage
is nil but testImage2
is a NSImage
instance. I don't know what's wrong with the code. I'm sure I can find logo64x64.png
and [email protected]
in the resource directory in the bundle. I've also tried imageNamed:@"logo64X64.png"
but still getting nil.
Anyone can help?
Upvotes: 2
Views: 3755
Reputation: 22948
Try
[NSImage imageNamed:@"logo64x64"];
rather than
[NSImage imageNamed:@"logo64X64"];
Note that in the code that succeeded, you used a lowercase x
, whereas in the code that failed, you used an uppercase X
(logo64X64
). NSBundle
is case-sensitive, even if the underlying HFS+ file system is only case-preserving. (NSImage
's +imageNamed:
method uses NSBundle
to locate resources).
Upvotes: 10