View Full Version : Image Access Problem in Xocde Screen saver project.

Mar 26, 2009, 06:10 AM
Hi Everyone

I am new to MAC Programming. I have just spend two days in it. Now, I have created simple Screen saver project from XCode.

I have put my all required images in the Resource folder of my project. Now,I want to access those images in my code. I don't know how to access these images from resource folder.

If I use Absolute path then it works fine, but when I uses any other relative path it doesn't work. Can you tell me what will be relative path for my images?

Assume I have "test.jpg" file in my resource folder of Screensaver project. When I will build the project,it will give me (TestScreenSaver.saver) file.

What will be my relative path for this project.

I will appreciate any help.

Thanks and Regards
Deep Bhavsar

Mar 26, 2009, 08:55 AM
Normally you'd use NSString *imagePath = [[NSBundle mainBundle] pathForImageResource:@"test.jpg"]; but mainBundle would return the bundle of whatever is loading your screensaver plugin, so try NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForImageResource:@"test.jpg"];

Mar 26, 2009, 11:46 PM
Hi kainjow

Thanks for your valuable reply. I was trying with [NSBundle mainBundle] and it was not working.

I had tried with your code and I got my problem solved. :)

Dipesh Bhavsar