IOS multiple Uiimageview loading HD large image memory management

Source: Internet
Author: User

When we are in a certain view of multiple Uiimageview, and Uiimageview are displaying a large HD image, there is a possibility of a memory warning issue. If you enter this view for the first time, there is no memory warning, and when you enter this view again, if the last memory is not released in time, this accumulation will cause memory to crash.


1,uiimage how to load pictures.

If it is a local picture, try not to use [UIImage Imagenamed:nil]; This way, if it is loaded in this way, it will always be in memory as long as the program does not exit.

We can use:

                      < strong>   nsstring  *path = [[ nsbundle mainbundle] Pathforresource:@ ' "The name of the picture" &NBSP; oftype: @ ""

UIImage *image = [UIImageimagewithcontentsoffile:p Ath];


The pros and cons of both are obvious, [UIImage Imagenamed:nil]; It just loads once, it's in memory, so the second load is fast. The second load mode is loaded again because we have freed it. So choose that way, depending on your situation.


2, said the second way, although can be released, but we have to tell people when to release. That is, when the current display page is not the view, we release it:

-(void) Viewwilldisappear: (BOOL) animated{

[Uiimageview removefromsuperview];

Uiimageview = Nil;

}


Of course, when we enter this view again, we have to add the removed view again.

-(void) Viewdidappear: (BOOL) animated{

[Self addsubview:uiimageview];

}


3, the above two methods, mainly to solve the problem of memory accumulation. But if you enter view for the first time, the image is all rendered on the view and the memory crashes. Then we can only have a fuss on the picture. We load the big picture of high-definition if it is almost 3000*2000, may be larger than this, even if our program is the IPad App,ipad 4 resolution, these graphs are much larger than the resolution of the device, is completely a waste of resources, so we usually a practice, is to render such a figure to a view in a small size.


Recommended Use:

Uiimage+resize.h, UIIMAGE+RESIZE.M
Extends the UIImage class to support resizing (optionally preserving the original aspect ratio), cropping, and Gener ating thumbnails.

Uiimage+roundedcorner.h, UIIMAGE+ROUNDEDCORNER.M
Extends the UIImage class to support adding rounded corners to an image.

Uiimage+alpha.h, UIIMAGE+ALPHA.M
Extends the UIImage class with helper methods for working with Alpha layers (transparencies).


Common methods:

UIImage *image

UIImage *thumbimage = [Imagethumbnailimage:+// This should the size of the view in collection view. Example:mycell width is, and height is 20.

transparentborder:0

Cornerradius:0

interpolationquality:kcginterpolationmedium]; Generate thumbnail images



This "resizedimage" image is a want to pass to SetImage

UIImage * resizedimage = [Imageresizedimage: ImageView. Frame. size   interpolationquality: kcginterpolationlow]; Create a diagram of the size you want



Caused by the problem, pay attention to the scale of the scale, do not cause the picture deformation, due to size reduction, may result in blurred images, attention to reduce the size.



It is obvious that each method has advantages and disadvantages. Mainly according to their own development situation, the compromise use.

IOS multiple Uiimageview loading HD large image memory management

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.