Reputation: 1367
I have a ScreenSaver project. In the Resources of this project presents the image file. I'm trying to load it like this:
NSString* imageName = [[NSBundle mainBundle] pathForResource:@"DefaultImage" ofType:@"jpg"];
mpCurrentImage = [[NSImage alloc] initWithContentsOfFile:imageName];
But the path of mainBundle is /Applications/System Preferences.app/Contents/Resources
How to get the path to the .saver bundle, to load the image from recourses?
Upvotes: 1
Views: 542
Reputation: 2993
You'd want to use
NSString* imageName = [[NSBundle bundleForClass:[self class]] pathForResource:@"DefaultImage" ofType:@"jpg"];
assuming that this code is in a class belonging to the bundle.
Upvotes: 7