iOS裁剪图片方式

//返回裁剪区域图片

-(UIImage*)clicpViewWithRect:(CGRect)aRect { //arect 想要截图的区域

    CGFloat scale = [UIScreen mainScreen].scale;


    aRect.origin.x*= scale;


    aRect.origin.y*= scale;


    aRect.size.width*= scale;


    aRect.size.height*= scale;


    UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.view.width, self.view.height), YES, scale);


    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];


    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();


    UIGraphicsEndImageContext();


    CGImageRefimageRef = viewImage.CGImage;


    CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, aRect);


    UIImage*sendImage = [[UIImagealloc]initWithCGImage:imageRefRect];


    returnsendImage;


}

你可能感兴趣的:(iOS裁剪图片方式)