imageNamed vs imageWithContentsOfFile

Posts: 39
Joined: 2008.09
Post: #1
I've changed one to another, and discovered that imageWithContentsOfFile is much slower than imageNamed, probably about 2-2.5 times. Is it normal? Any ideas how to avoid caching and still retain speed?
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #2
I haven't noticed any difference in loading times myself, although I've been careful not to be loading anymore images than immediately needed.

Instead of using the UIImage routines, you can do something like this instead:

CGImageRef        image;
CGDataProviderRef    source;
source = CGDataProviderCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:myImageName ofType:@"png"]]);
image = CGImageCreateWithPNGDataProvider(source, nil, NO, kCGRenderingIntentDefault);

[adding] Oh yeah, and don't forget to release them yourself once you're done loading, with:

Quote this message in a reply
Post Reply