http://blog.csdn.net/ch_soft/article/details/8245944
第一种解决方法:选择适当的加载方式
在程序的开发过程中,经常会用到很多的图片,适当的选择加载图片的方式就显得格外的重要,如果选择不得当,很容易造成内存吃紧而引起程序的崩溃。
这里介绍一下几种常见的加载方式:
用UIImage加载图像的方法很多,最常用的是下面两种:
一、用imageNamed函数
引用
[UIImage imageNamed:ImageName];
二、用NSData的方式加载,例如:
引用
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *image = [NSData dataWithContentsOfFile:filePath];
[UIImage imageWithData:image];
三,使用[UIImage imageWithContentOfFile:] 或者[image initWithContentOfFile:]
引用
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"图片扩展名"];
[UIImage imageWithContentsOfFile:aImagePath];