#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.