zoukankan      html  css  js  c++  java
  • 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"]];


  • 相关阅读:
    数据访问(从数据库中访问数据)
    加载类、设计模式(单例模式和工厂模式)
    面向对象之静态
    面向对象三大特性之继承和多态
    面向对象三大特性之封装
    面向对象基础知识
    mysql下载与安装过程
    Idea添加依赖的步骤:
    Java JDBC 在IDEA环境下连接MySQL
    JAVA中集合HashMap嵌套联系
  • 原文地址:https://www.cnblogs.com/cnsoft/p/1363032.html
Copyright © 2011-2022 走看看