+ (UIImage *)imageNamed:(NSString *)name方法是在application bundle的顶层文件夹寻找名字的图象 , 如果找到图片, 系统缓存图象。图片内容被加载到系统内存中,使用时直接引用到系统内存。
所以当处理大量图片时,程序使用的内存会迅速上升导致内存警告并退出。
NSString *path = [[NSBundle mainbundle] pathForResource:@"Chen" ofType:@"png"];
当然,对于图片处理等相关程序,可以直接为UIImage写一个catagory,重载imageNamed方法,如下:
+ (UIImage *)imageNamed:(NSString *)name
{
return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], name ] ];
}
@end
iOS imageNamed与imageWithContentsOfFile 图片
猜你喜欢
转载自chenwangyi.iteye.com/blog/2093528
今日推荐
周排行