美文网首页
iOS UIView转成图片总结

iOS UIView转成图片总结

作者: ___1o_8o | 来源:发表于2017-11-22 10:53 被阅读136次
- (UIImage *)shotShareImage {
        //模糊方法
        UIGraphicsBeginImageContext(CGSizeMake(self.layer.bounds.size.width, self.layer.bounds.size.height));
        CGContextRef context = UIGraphicsGetCurrentContext();
        [self.layer renderInContext:context];
        UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return tImage;
        
        //高清方法
        //第一个参数表示区域大小 第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
        CGSize size = CGSizeMake(self.layer.bounds.size.width, self.layer.bounds.size.height);
        UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    
}

相关文章

网友评论

      本文标题:iOS UIView转成图片总结

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