美文网首页iOS
iOS裁剪图片方式

iOS裁剪图片方式

作者: zym_ | 来源:发表于2016-07-25 17:25 被阅读9695次

    //返回裁剪区域图片

    -(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裁剪图片方式

        本文链接:https://www.haomeiwen.com/subject/pwagjttx.html