tags:

views:

1230

answers:

1

I want to get image from IImage object from specified path location.Here is the code .

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  
                                                         NSUserDomainMask,   YES);

NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"image1.png"];
NSLog(writablePath);
UIImage *image=[UIImage imageNamed:writablePath];

I get image object nil. so what could be the problem? I have also varified that image1.png is there at writablePath.

+3  A: 

I believe UIImage imageNamed looks for images from the application bundle, rather than by full path. You can use UIImage imageWithContentsOfFile to load from a full path (but it won't be cached), or just put the image in your bundle and use imageNamed.

You also need to check that the file is actually being placed in your application bundle, and is not just sitting in your project directory.

Adam Wright
Do you know if it is possible to use imageNamed: when loading images from the caches folder (NSCachesDirectory) ?
Martijn Thé