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 ~