1

我有一个屏幕保护程序项目。在这个项目的资源中展示了图像文件。我正在尝试像这样加载它:

NSString* imageName = [[NSBundle mainBundle] pathForResource:@"DefaultImage" ofType:@"jpg"];
mpCurrentImage = [[NSImage alloc] initWithContentsOfFile:imageName];

但是 mainBundle 的路径是 /Applications/System Preferences.app/Contents/Resources

如何获取 .saver 包的路径,以从资源中加载图像?

4

1 回答 1

7

你想用

NSString* imageName = [[NSBundle bundleForClass:[self class]] pathForResource:@"DefaultImage" ofType:@"jpg"];

假设此代码在属于该捆绑包的类中。

于 2013-06-30T14:39:38.030 回答