Image Access Problem in Xocde Screen saver project.

Discussion in 'Mac Programming' started by DeepBhavsar, Mar 26, 2009.

  1. macrumors newbie

    Joined:
    Mar 26, 2009
    #1
    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
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Normally you'd use
    Code:
    NSString *imagePath = [[NSBundle mainBundle] pathForImageResource:@"test.jpg"];
    but mainBundle would return the bundle of whatever is loading your screensaver plugin, so try
    Code:
    NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForImageResource:@"test.jpg"];
     
  3. thread starter macrumors newbie

    Joined:
    Mar 26, 2009
    #3
    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. :)



    Thanks
    ----------------
    Dipesh Bhavsar
     

Share This Page