Clipping of iOS pictures

Source: Internet
Author: User

-(void) Tailoring {

UIImage *oldimage = [UIImage imagenamed:@ "implements the picture that is ready to be cropped. png"];

CGFloat borderw = 2;

CGFloat Imagew = oldImage.size.width + borderw * 2;

CGFloat Imageh = oldImage.size.height + borderw * 2;

Uigraphicsbeginimagecontextwithoptions (Cgsizemake (Imagew, Imageh), NO, 0.0);

Cgcontextref CTX = Uigraphicsgetcurrentcontext ();

Ring

CGFloat CenterX = Imagew * 0.5;

CGFloat centery = Imageh * 0.5;

Cgcontextaddarc (CTX, CenterX, CenterY, CenterX, 0, M_PI * 2, 0);

[[Uicolor Whitecolor] set];

Cgcontextfillpath (CTX);

Cutting

CGFloat radius = oldImage.size.width * 0.5;

Cgcontextaddarc (CTX, CenterX, centery, radius, 0, M_PI * 2, 0);

Cgcontextclip (CTX);

Drawing

[Oldimage Drawinrect:cgrectmake (Borderw, Borderw, OldImage.size.width, OldImage.size.height)];

UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

NSData *data = uiimagepngrepresentation (newimage);

[Data writetofile:@ "path/Picture name. png" Atomically:yes];

}

Clipping of iOS pictures

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.