Once, I placed all my pictures in APP Bundle. I used imageNamed function to get an image. Later, I decided to copy some pictures to the Document when app start. So, I could not use imageNamed function to get an image any more. I used imageWithContentsOfFile to get an image:
NSString* documentsDirectoryPath =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
UIImage* result =[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", documentsDirectoryPath, fileName, extension]];
However, imageWithContentsOfFile return a low quality image (very fuzzy). all of my image are 128*128. I used following code the detect the size of the picture:
NSData * imgData = UIImagePNGRepresentation(image);
NSLog(@"size : %d",[imgData length]);
I found that size of the image returned by imageNamed is 3 times than imageWithContentsOfFile. I got crazy ... Help me ! Thanks a lot ...
In the UIImage reference documentation you can see a couple of differences between imageNamed and imageWithContentsOfFile.
Knowing this, the most logical explanation that I can think of for your problem is that you are using a retina device and have a retina version of that same image (@2x). That would explain why the image
I use
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
in order to load images from disk without caching them, to reduce memory footprint.It seems that this method has changed since iOS 8x. In order to maintain functionality on each iOS version (7x to 9x), I use this simple category on UIImage :
And .m
Hope that helps ;)