How iOS makes an avatar picture a circle

Source: Internet
Author: User
Tags border color

+ (UIImage *) Imagedrawcirclewithimage: (UIImage *) originimage{cgfloat padding=5;//the margin of a circular image from an imageUicolor* Epsbackcolor = [Uicolor Greencolor];//background color of the imagecgsize originsize=originimage. Size; CGRect Originrect= CGRectMake (0,0, originsize. Width, originsize. height);        Uigraphicsbeginimagecontext (originsize); Cgcontextref CTX=Uigraphicsgetcurrentcontext (); //The target area. CGRect Desrect= CGRectMake (padding, padding,originsize. Width-(padding*2), Originsize. Height-(padding*2 )); //sets the fill background color. Cgcontextsetfillcolorwithcolor (CTX, Epsbackcolor.        Cgcolor); Uirectfill (Originrect); //the real fill//sets the ellipse deform area. Cgcontextaddellipseinrect (Ctx,desrect); Cgcontextclip (CTX); //intercepts elliptical regions. [Originimage Drawinrect:originrect];//draws the image in the target area. UIImage* Desimage =Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext (); returnDesimage; }+ (UIImage *) Imagedrawcircleedgewithimage: (UIImage *) originimage{cgfloat padding=5;//the margin of a circular image from an imageUicolor* Epsbackcolor = [Uicolor Greencolor];//background color of the imagecgsize originsize=originimage. Size; CGRect Originrect= CGRectMake (0,0, originsize. Width, originsize. height);        Uigraphicsbeginimagecontext (originsize); Cgcontextref CTX=Uigraphicsgetcurrentcontext (); //The target area. CGRect Desrect= CGRectMake (padding, padding,originsize. Width-(padding*2), Originsize. Height-(padding*2 )); //sets the fill background color. Cgcontextsetfillcolorwithcolor (CTX, Epsbackcolor.        Cgcolor); Uirectfill (Originrect); //the real fill//sets the ellipse deform area. Cgcontextaddellipseinrect (Ctx,desrect); Cgcontextclip (CTX); //intercepts elliptical regions. [Originimage Drawinrect:originrect];//draws the image in the target area. //Border//cgfloat borderWidth=Ten ; Cgcontextsetstrokecolorwithcolor (CTX, [Uicolor Whitecolor]. Cgcolor); //Set Border colorCgcontextsetlinecap (CTX, Kcglinecapbutt); Cgcontextsetlinewidth (CTX, borderWidth); //sets the border width. Cgcontextaddellipseinrect (CTX, desrect);//Draw a circle in this boxCgcontextstrokepath (CTX);//The stroke border. //Border//UIImage* Desimage = Uigraphicsgetimagefromcurrentimagecontext ();//gets the image in the context of the current drawing. Uigraphicsendimagecontext (); returndesimage;}

How iOS makes an avatar picture a circle

Related Article

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.