zoukankan      html  css  js  c++  java
  • iOS_UIImage中 + imageNamed: 和 + imageWithContentsOfFile 二者之间的区别

    这2种方式是我们长使用的加载一张图片的方法,但是他们之间有什么去区别呢?

    官方文档:

    /**
     * @brief   Returns the image object associated with the specified filename.
     *
     * @param   <name>  The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle. 
     *
     * @return  The image object for the specified file, or nil if the method could not find the specified image.
     */
    
    + (UIImage *)imageNamed:(NSString *)name
    
    /**
     * @brief   Creates and returns an image object by loading the image data from the file at the specified path.
     *
     * @param <path>    The full or partial path to the file
     *
     * @return A new image object for the specified file, or nil if the method could not initialize the image from the specified file.
     */
    
    + (UIImage *)imageWithContentsOfFile:(NSString *)path
    

     说下区别吧:

    + (UIImage *)imageNamed:(NSString *)name 加载图片,首先从系统缓存中查找, 如果缓存中没有, 再从磁盘或者资源目录中加载图片数据,生成image对象返回.同时, Apple官方提示此方法不确保线程的安全.

    + (UIImage *)imageWithContentsOfFile:(NSString *)path 加载图片:此方法不会缓存图片对象. 在一定情况下, 会提高APP的内存使用效率.


  • 相关阅读:
    WinMain函数的修饰符WINAPI的含义
    java字节码指令集简介
    vs2010里面的ipch文件和.sdf文件是什么
    java查看class字节码文件
    从汇编看c++的extern关键字
    highcharts系列教程
    highcharts的文档介绍(英文)
    关于firebug中行号和源文件不一致的问题
    ios中的流状态的定义
    highcharts翻译系列
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5752142.html
Copyright © 2011-2022 走看看