chdtyzhy

IOS中无缓存的图片载入

在IOS中,我们常用[UIImage imageNamed]方法获取图像,这种方法简便,容易理解。但是有个缺点,就是有缓存。这种方式
传人的图像的就是通过文件名方式文件名。如果,我们内存有限,我们就必须考虑内存问题。

// imageNamed: 有缓存(传入文件名)
UIImage *image = [UIImage imageNamed:filename];
如果我们采用传人文件全路径的方式,imageWithContentsOfFile这种方法,就是没有缓存。
所谓文件的全路径是相对于手机,不是对于电脑。这个是要注意的
// imageWithContentsOfFile: 没有缓存(传入文件的全路径)
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:filename ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];

 

//还补充其他:

我们一般会把数据放在一些文件中,如txt,plist

如果我们要从plist文件中获取数据,我们也可以采用全路径的方法。

 

NSBundle *bundle=[NSBundle mainBudle];
NSString *path=[path pathForResource:filename ofType:prlist];
_imgeData=[NSArray arrayWithContentsofFile:path];
这是获取图片文件的方法,
NSBundle *bundle=[NSBundle mainBudle];
NSString *path=[path pathForResource:filename ofType:nil];
_image=[UIIamge imageWithFile:path];
其实oc的Foundaton框架,对这些方法都写得简单

 

posted on 2014-03-26 01:21  勇@  阅读(360)  评论(0编辑  收藏  举报

导航