Several ways to stretch iphone pictures
Uiimageresizingmodetile and Uiimageresizingmodestretch two modes, from the name can be seen, is the tiling mode and stretching mode. Tiling is the insets of the rectangular area you specify to fill the area of the picture you specify, and the stretch is to fill the area of the picture you want by stretching the block of rectangular area you insets specify.
After the system has been IOS6, the method of image stretching has been extended to 3 functions:
1.ios4 provides the method:
- -(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) topcapheight
- This function is an instance of UIImage function, its function is to create a content can be stretched, and the corner does not stretch the picture, need two parameters, the first is not stretch the width of the area from the left border, the second parameter is not stretched the width of the area distance, its operation is the nature of a pixel copy stretching, Therefore, there is no gradient effect, which is also its disadvantage.
- The meaning of the parameter is if the parameter specifies 10, 5. So, the picture on the left 10 points, the top 5 points. Will not be stretched, points with an X coordinate of 11 will be copied horizontally, and a point with a Y coordinate of 6 will be copied vertically.
注意:只是对一个点像素进行复制到指定的宽度。
Reference: http://www.linuxidc.com/Linux/2013-02/80113p2.htm
Methods provided by 2.IOS5
- -(UIImage *) Resizableimagecapinsets: (uiedgeinsets) Insets
- where insets the format of this parameter is (top,left,bottom,right), from the top, left, bottom and right, respectively, draw a line on the picture, so that a picture is assigned a rectangular area. Only the part inside the box is stretched, and the outside of the box remains unchanged. For example (20,5,10,5), meaning that the inner part of the rectangle can be stretched, while the rest remains unchanged.
3.IOS6 provides the method:
- -(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets Resizingmode: (uiimageresizingmode) ResizingMode With respect to the insets parameter, the IOS5 is the same, and the difference is that after adding a stretched pattern, the ios6.0 version provides uiimageresizingmodetile and Uiimageresizin Gmodestretch two modes, from the name can be seen, is the tiling mode and stretching mode. Tiling is the insets of the rectangular area you specify to fill the area of the picture you specify, and the stretch is to fill the area of the picture you want by stretching the block of rectangular area you insets specify. I think, compared with the progress of 4.0 you also see, is obvious, compared to the previous, the image of the resize from a point into a rectangular block, so that your specified block of the gradient effect can be presented.
- Just, if you need to be compatible with 4.0 of the machine, then it is necessary to use the old function to complete the resize operation of the picture.
Several ways to stretch iphone pictures