Reputation: 15274
I'm trying to create image from this location :
NSString *documentsCacheDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *fileName = @"image1.jpg";
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsCacheDirectory, fileName];
So applying to my Image :
UIImage *myImage = [UIImage imageNamed:filePath];
..setting this image as background to my button etc. etc.
But I'm not seeing any images displayed. However when I use the same technique for reading a file :
NSString *documentsCacheDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *fileName = @"file.txt";
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsCacheDirectory, fileName];
NSString *fileContents = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
for (NSString *line in [cacheFileContents componentsSeparatedByString:@"\n"]) {
.....
}
Reading file works just fine, but image does not, any reasons why?
Upvotes: 0
Views: 200
Reputation: 53551
imageNamed:
is for images that are bundled with your app, you don't use this with a path. Use imageWithContentsOfFile:
instead.
Upvotes: 2