UIImage initialization Difference Two methods Introduction (interview Common) _android

Source: Internet
Author: User

UIImage can be initialized in the following two ways:

The first way to initialize: "Note that when using this initialization, if PNG format can not give suffix name, according to the resolution of the screen to match the picture"
uiimage *image = [UIImage imagenamed:@ v_red_heart_ Selected "]; 
The second way to initialize: "You must splice the full name of the picture, otherwise the image's path is empty"
nsstring *filepath = [[NSBundle mainbundle] pathforresource:@ "V_red_heart_ Selected@x.png "Oftype:nil]; 

The difference between two ways:

 The first way to initialize:

Using imagenamed: First time reading, put the picture in the cache, the next time you use the same name of the picture to read directly from the cache; advantages: Convenient and quick, only the first time to use a little slower, then use will be a little faster Disadvantage: If only one time is used in the current project, memory will be wasted. "The inside of this program is closed before it is released."

 The second method of initialization:

When you initialize a picture using Initwithcontentsoffile, each time you read it according to the path, it does not occupy memory, and you should choose this method if the picture is used only once in the current project.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.