Briefly describe how to create UIImage in OC ~~~, Ocuiimage

Source: Internet
Author: User

Briefly describe how to create UIImage in OC ~~~, Ocuiimage

1. directly use imageNamed for Creation

1 UIImage * image = [UIImage imageNamed: @ "1.jpg"];

Briefly describe the advantages and disadvantages of this method:

Advantage: a single line of code can be done with a small amount of code. When this image is loaded multiple times in the program, the system points to the same memory, which improves the efficiency.

Disadvantage: The system caches images to the memory of the computer every time. If the image is very large, it will consume a lot of computer memory and cause freezing.

 

2. convert local images to NSData Storage

1     NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"jpg"];2     NSData *imageData = [NSData dataWithContentsOfFile:filePath];3     UIImage *image1 = [UIImage imageWithData:imageData];

Advantage: images will be loaded into the program as data by the system. When you do not need to reuse an image or you need to load a large number of images, it will not consume a lot of computer memory, this method is used.

Disadvantage: there is a large amount of code, which is not the first simple.

 

3. Obtain network images through NSURL

1     NSURL *url = [NSURL URLWithString:PATH];2     NSData *imageData = [NSData dataWithContentsOfURL:url];3     UIImage *image = [UIImage imageWithData:imageData];

The PATH above is the address of the network image.

The advantages and disadvantages of this method are the same as those of the second method. The difference is that the method for obtaining images is different.

 

Writing is very simple. I hope you can exchange and learn from each other ~ Thank you ~

 

Related Article

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.