ios-cropping and clipping strokes plus clipping into a method class

Source: Internet
Author: User
Tags uikit

////uiimage+uitool.h//Picture Clipping////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<UIKit/UIKit.h>@interfaceUIImage (Uitool)+ (Instancetype) Imagewithname: (NSString *) name border: (cgfloat) Border bordercolor: (Uicolor *) color;@end////UIIMAGE+UITOOL.M//Picture Clipping////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "uiimage+uitool.h"@implementationUIImage (Uitool)+ (Instancetype) Imagewithname: (NSString *) name border: (cgfloat) Border bordercolor: (Uicolor *) color{cgfloat borderw=border; UIImage*oldimage =[UIImage Imagenamed:name]; CGFloat Imagew= OldImage.size.width +2*Borderw; CGFloat Imageh= oldimage.size.height+2*Borderw; CGFloat CIRCIRW= Imagew > Imageh?Imageh:imagew; Uigraphicsbeginimagecontextwithoptions (Cgsizemake (CIRCIRW, CIRCIRW), NO,0.0); Uibezierpath*path = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0,0, CIRCIRW, CIRCIRW)]; Cgcontextref CTX=Uigraphicsgetcurrentcontext (); Cgcontextaddpath (CTX, path.)    Cgpath); [ColorSet];        Cgcontextfillpath (CTX); CGRect CLIPR=CGRectMake (Borderw, Borderw, OldImage.size.width, oldImage.size.height); Uibezierpath*clippath =[Uibezierpath BEZIERPATHWITHOVALINRECT:CLIPR];        [Clippath Addclip];        [Oldimage Drawatpoint:cgpointmake (Borderw, BORDERW)]; UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext (); returnnewimage;}@end
////VIEWCONTROLLER.M//Picture Clipping////Created by Yaguangzhu on 15/9/10.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "uiimage+uitool.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview*ImageView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib. //White Ring Edition_imageview.image = [UIImage imagewithname:@"001"BorderTenBordercolor:[uicolor Redcolor]]; }- (void) clipcrile{cgfloat borderw=5; UIImage*oldimage = [UIImage imagenamed:@"001"]; CGFloat Imagew= OldImage.size.width +2*Borderw; CGFloat Imageh= oldimage.size.height+2*Borderw; CGFloat CIRCIRW= Imagew > Imageh?Imageh:imagew; Uigraphicsbeginimagecontextwithoptions (Cgsizemake (CIRCIRW, CIRCIRW), NO,0.0); Uibezierpath*path = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0,0, CIRCIRW, CIRCIRW)]; Cgcontextref CTX=Uigraphicsgetcurrentcontext (); Cgcontextaddpath (CTX, path.)    Cgpath); [[Uicolor Whitecolor]Set];    Cgcontextfillpath (CTX); CGRect CLIPR=CGRectMake (Borderw, Borderw, OldImage.size.width, oldImage.size.height); Uibezierpath*clippath =[Uibezierpath BEZIERPATHWITHOVALINRECT:CLIPR];        [Clippath Addclip];        [Oldimage Drawatpoint:cgpointmake (Borderw, BORDERW)]; UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext (); _imageview.image=newimage;}- (void) clip{UIImage*oldimage = [UIImage imagenamed:@"001"]; Uigraphicsbeginimagecontextwithoptions (Oldimage.size, NO,0.0); Uibezierpath*path = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0,0, OldImage.size.width, OldImage.size.height)];        [Path Addclip];        [Oldimage Drawatpoint:cgpointzero]; UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext ();        Uigraphicsendimagecontext (); _imageview.image=newimage;}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

ios-cropping and clipping strokes plus clipping into a method class

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.