Loading an image from local resources

Discussion in 'iOS Programming' started by kmo19, May 18, 2009.

  1. kmo19 macrumors member

    Joined:
    Jan 7, 2009
    #1
    I know I can just use UIImage imageNamed:
    But how would I do it using file paths? I've tried many variations of this:

    Code:
    NSString* imgName = @"test.png";
    NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
    NSURL *url = [NSURL fileURLWithPath:[resourcePath stringByAppendingString:imgName]];
    
    NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Look into UIImage's imageWithContentsOfFile:
     

Share This Page