imageNamed vs imageWithContentsOfFile

imageNamed vs imageWithContentsOfFile

昨天更新了 2.2SDK 模拟器声音不正常的问题解决了。 但又发现一个新问题. 也许是个Bug。

模拟器上. 如果  

UIImage *cover = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"images/cover.png" ofType:nil] ] ;
 注意.  path 是 "images/cover.png" 带目录的.. 模拟器就会报错了.

而真机不会.

 

找到根源了:: 是 pathForResource 函数的使用问题,,

NSString* str = [[NSBundle mainBundle] pathForResource:@"cover.png" ofType:nil inDirectory:@"images"]; 用这个就好了。。soga!!!

google了一下, 因为看到, ImageNamed 占用的内存较多, 而后者比较节省内存, 但是加载速度慢。所以才做的修改。 没想到一下就被模拟器打到了。。。

无语。。 看这个Slow UIImage 看来还是要合理应用才行啊, 以后有了新的再总结一下吧

 

看来真机和模拟器的差异是永远存在的,也是最影响开发效率的一个环节。貌似2.0SDK的模拟器没问题 但是我不确定因为我在用2.0的时候没有修改这个加载的函数。莫名其妙的 EXEC_BAD_ACCESS 是最麻烦的错误。。。

 

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:

CGImageRelease(image);
CGDataProviderRelease(source);

 

 temp3 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mapNEW" ofType:@"png"]];


 

转载于:https://www.cnblogs.com/cnsoft/archive/2008/12/26/1363032.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值