IOS Picture clipping (encapsulating data)

Source: Internet
Author: User

Package: Generate Avatar (UIImage (NJ). h/. M

@interface UIImage (NJ) /* * *   Generate avatar * *  @param icon   avatar picture name *  @param border avatar Border size *  @param  color of the picture border * *   c11>*/+ (instancetype) Imagewithicon: (NSString *) icon border: (nsinteger) Border color: (Uicolor *) color; @end
View Code
@implementationUIImage (NJ)+ (Instancetype) Imagewithicon: (NSString *) icon border: (nsinteger) Border color: (Uicolor *) color{//0. Load the original imageUIImage *image =[UIImage Imagenamed:icon]; //1. Create a picture contextCGFloat margin =border; Cgsize size= Cgsizemake (image.size.width + margin, Image.size.height +margin); //YES Opaque no transparentUigraphicsbeginimagecontextwithoptions (Size, NO,0); //2. Draw a great circleCgcontextref CTX =Uigraphicsgetcurrentcontext (); Cgcontextaddellipseinrect (CTX, CGRectMake (0,0, Size.width, size.height)); [ColorSet];        Cgcontextfillpath (CTX); //3. Draw a small CircleCGFloat smallx = margin *0.5; CGFloat smally= Margin *0.5; CGFloat SMALLW=Image.size.width; CGFloat SMALLH=Image.size.height;    Cgcontextaddellipseinrect (CTX, CGRectMake (Smallx, smally, SMALLW, SMALLH)); //[[Uicolor Greencolor] set]; //Cgcontextfillpath (CTX); //4. The scope of the guidance available, the scope of application of the scope is after the designation, also said in the range of the specified cut before the thing is not affectedCgcontextclip (CTX); //5. Drawing pictures[Image Drawinrect:cgrectmake (Smallx, smally, SMALLW, SMALLH)]; //6. Remove the imageUIImage *newimage =Uigraphicsgetimagefromcurrentimagecontext (); returnnewimage;}
View Code

Call

@property (Weak, nonatomic) iboutlet Uiimageview *IV; @end @implementation Njviewcontroller-(void) viewdidload{    [Super Viewdidload];     Imagewithicon:@ "me" border:  color:[uicolor Greencolor]] ; =         newimage;    }

IOS Picture clipping (encapsulating data)

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.