-(Void) circleheadportrait
{
// 1. Load the source Image
Uiimage * oldimage = [uiimage imagenamed: @ "me"];
// 2. Enable a context of the same size as the image, that is, enable a new image. The size of the new image is the same as that of the original image.
Uigraphicsbeginimagecontextwitexceptions (oldimage. Size, no, 0.0 );
// 3. Obtain the current context
Cgcontextref CTX = uigraphicsgetcurrentcontext ();
// 4. Circle
Cgrect circlerect = cgrectmake (0, 0, oldimage. Size. Width, oldimage. Size. Height );
Cgcontextaddellipseinrect (CTX, circlerect );
// 5. Crop according to the current path shape (Circular). content beyond this shape is not displayed
Cgcontextclip (CTX );
// 6. Drawing
[Oldimage drawinrect: circlerect];
// 7. Obtain the image
Uiimage * newimage = uigraphicsgetimagefromcurrentimagecontext ();
// 8. End
Uigraphicsendimagecontext ();
// 9. Write the file
Nsdata * Data = uiimagepngrepresentation (newimage );
Nsstring * Path = [[nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) lastobject] stringbyappendingpathcomponent: @ "new.png"];
[Data writetofile: path atomically: Yes];
// 10. display the image
Self. iconview. Image = newimage;
}
Create a QQ Avatar with a white border using quztrz2d