IOS UIImage (reprint)

Source: Internet
Author: User

UIImage is a more difficult way to display pictures, UIImage can display pictures from a file or ImageData. If you can graphically operate, it is recommended to use the ImageView Control to display the picture, after all, is a graphical visual operation.

When creating a picture from ImageData, be sure to pay attention to the size and size of the image, because this is in memory, if the picture is too large or too many pictures, it is easy to cause memory leaks, if you choose a picture from a file, you can manually select whether the picture is in memory.
The UIImage supported image types are: TIFF,TIF,JPG,JPEG,GIF,PNG,BMP,BMPF,ICO,CUR,XBM. UIImage commonly used to load pictures from a file in the following ways: 1. + (UIImage *) imagenamed: (NSString *) nameFeatures: The most convenient, the most efficient way to load pictures. However, the use of this way to load the picture, after the first load, the picture will be cache in memory, so there is a certain risk of memory leaks, must not be loaded too large or disposable folder in too many pictures, and immediately after the use of memory release; Parameter name, the file name, if the picture is stored in the project path in the sub-physical folder, you only need to specify the file name, the system will automatically find the sub-directory of the picture. 2. + Imagewithcontentsoffile:or-(ID) Initwithcontentsoffile: (NSString *) path features: Use more code, but will not cache the picture in memory, but need to provide pictures of For the specific path and picture name sample code, set the background picture for the current Viewcontroller (Uiviewcontroller):
// Set the current  Viewcontroller (uiviewcontroller) Background image     // First method UIImage *bgimage = [UIImage imagenamed:  @ "bg.png"= [Uicolor colorwithpatternimage:bgimage];     // The second method of NSString *path = [[NSBundle mainbundle] Pathforresource:@ "bg.png" oftype:nil Indirectory:@ ""*bgimage2 == [Uicolor colorwithpatternimage:bgimage2];

Transferred from: http://www.cnblogs.com/xunziji/archive/2012/09/25/2701928.html

Do not quite understand how the author so hate reprint, anyway I was turned, keep the good check later.

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.