iOS development--image processing

Source: Internet
Author: User

Throughout the real world and mobile app market, this is a face-looking era, and the beautiful and pretty app interface is the mobile app's face. The beautiful appearance behind the UI designer's hard work, if not understand the processing, wasted the UI designer's efforts.

For example, the following picture is used to make a button image

Size: 59 * 32

Show it as a picture first, the picture display position is set to 200 * 50

1  #import "ViewController.h"2   3   @interfaceViewcontroller ()4   5   @end6   7   @implementationViewcontroller8   9- (void) Viewdidload {Ten [Super Viewdidload]; One      //stretching a picture A [self stretchphoto];  -  } -  the- (void) Stretchphoto -  { -Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake ( -, the, $, -)]; -Imageview.image = [UIImage imagenamed:@"Btnbg_blue.png"]; + [Self.view Addsubview:imageview]; -  } +   A  @end

It shows the following effects:

We can clearly see that the image lost its original appearance, especially the four corners, this is because the image itself size: 59 * 32, and set the picture display position of the size of 200 * 50, the picture was pulled out.

Here we set an extrude point for this image:

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One  A     //stretching a picture - [self stretchphoto]; - } the  - //stretching a picture -- (void) Stretchphoto - { +Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake ( -, the, $, -)]; - [Self.view Addsubview:imageview]; +      A     //set the stretch point of a picture atUIImage *images = [UIImage imagenamed:@"Btnbg_blue.png"];//* -Images = [Images stretchableimagewithleftcapwidth: -Topcapheight: -]; -Imageview.image =images; - } -  - @end

It shows the following effects:

It is clear to see that the picture is perfectly stretched to show.

Here's a detailed explanation of how to set up a picture extrude point:

1 -(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) Topcapheight; 2 @property (nonatomic,readonly) Nsinteger leftcapwidth;   // default is 0. If Non-zero, Horiz. stretchable. Right caps is calculated as Width-leftcapwidth-1 3 @property (nonatomic,readonly) Nsinteger topcapheight;   // default is 0. If Non-zero, vert. stretchable. Bottom caps is calculated as Height-topcapwidth-1

The above content is an explanation of the method in the Xcode document

Line 1th is the method name, the return value is UIImage object, need to pass two parameters of Nsinteger type;

Lines 2nd and 3rd are the two properties of the 1th row that need to pass the parameter, and the default is 0; from somewhere else, the two properties are called by a name: The end cover, which is the left cover width and the top cover height.

So it seems that stretching the picture, the left and the top are stretched, then right and bottom?

The API documentation gives the calculation formula:rightcapwidth = image.size.width-(image.leftcapwidth + 1); that is: The right end cover width = picture width-(left cover width + 1);

Bottomcapheight = Image.size.height-(image.topcapheight + 1); i.e.: bottom end cover = Picture high-(Top end cover + 1);

As shown in the following:

   

As you can see, the last stretched position is the area of 1 * 1 (the middle yellow area) next to the intersection of the left cover and the top end cover, that is, this method stretches only 1 * points of a given area.

In general, be accustomed to the position of a given picture width and height, so as not to know the edge changes caused by unnecessary trouble.

  

iOS Development--picture processing

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.