-(UIImage *) Imagecutwithrect: (cgrect) rect {cgimageref Subimageref=Cgimagecreatewithimageinrect (self. Cgimage, rect); CGRect Smallrect= CGRectMake (0,0, Cgimagegetwidth (Subimageref), Cgimagegetheight (Subimageref)); //turn on the graphics contextUigraphicsbeginimagecontext (smallrect.size); Cgcontextref Context=Uigraphicsgetcurrentcontext (); Cgcontextdrawimage (context, smallrect, subimageref); UIImage* Image =[UIImage Imagewithcgimage:subimageref]; //Close the graphics contextUigraphicsendimagecontext (); Cgimagerelease (SUBIMAGEREF); returnimage;}
Use
-(Uiimageview *) ImageView {if(_imageview = =Nil) {Self.imageview=[[Uiimageview alloc] init]; Self.imageView.backgroundColor=[Uicolor Redcolor]; UIImage* image = [UIImage imagenamed:@"1.jpg"]; //capture the original middle 300*300CGFloat CUTIMAGEWH = -; CGFloat cutimage_x= (Image.size.width- -) /2; CGFloat cutimage_y= (Image.size.height- -) /2; Self.imageView.image=[Image Imagecutwithrect:cgrectmake (cutimage_x, cutimage_y, CUTIMAGEWH, CUTIMAGEWH)]; } return_imageview;}
Ios_uiimage_ Picture Clipping