首页 > 移动平台 > 详细

IOS中无缓存的图片载入

时间:2014-03-26 05:27:33      阅读:541      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
bubuko.com,布布扣
在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];
bubuko.com,布布扣

 

bubuko.com,布布扣

//还补充其他:

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

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

 

bubuko.com,布布扣
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框架,对这些方法都写得简单
bubuko.com,布布扣

IOS中无缓存的图片载入,布布扣,bubuko.com

IOS中无缓存的图片载入

原文:http://www.cnblogs.com/zhyios/p/3624662.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!