Captures a picture of the middle rectangular area of a picture according to size the size here is square.

Source: Internet
Author: User

#pragma mark captures a picture of the middle rectangular area of a picture based on size the size here is square-(UIImage *) Cutcenterimage: (UIImage *) image size: (cgsize) size{cgsize imag    Esize = image.size;    CGRect rect; Calculates the position and size of the middle rectangular area of the picture according to the size of the image if (ImageSize.Width > Imagesize.height) {float LeftMargin = (imagesize.width-im        agesize.height) * 0.5;    Rect = CGRectMake (leftMargin, 0, Imagesize.height, imagesize.height);        }else{float TopMargin = (imagesize.height-imagesize.width) * 0.5;    Rect = CGRectMake (0, TopMargin, ImageSize.Width, imagesize.width); } cgimageref imageref = image.    Cgimage;        Capture the middle area rectangle picture Cgimageref imagerefrect = Cgimagecreatewithimageinrect (imageref, rect);    UIImage *tmp = [[UIImage alloc] initwithcgimage:imagerefrect];        Cgimagerelease (Imagerefrect);    Uigraphicsbeginimagecontext (size);    CGRect Rectdraw = CGRectMake (0, 0, size.width, size.height);    [TMP Drawinrect:rectdraw];   Creates a resized image from the current context tmp = Uigraphicsgetimagefromcurrentimagecontext ();     Make the current context out of the stack uigraphicsendimagecontext (); return TMP;}

Captures a picture of the middle rectangular area of a picture according to size the size here is square.

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.