美文网首页
通过渲染UIView 生成一个新的UIImage

通过渲染UIView 生成一个新的UIImage

作者: seventhboy | 来源:发表于2017-05-16 15:10 被阅读351次
  • (UIImage *)imageWithCaputureView:(UIView )view
    {
    CGSize size = CGSizeMake(view.bounds.size.width, view.bounds.size.height
    0.9);

    // 开启位图上下文
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);

    // 获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 把控件上的图层渲染到上下文,layer只能渲染
    [view.layer renderInContext:ctx];

    // 生成新图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // 关闭上下文
    UIGraphicsEndImageContext();

    return image;
    }

相关文章

网友评论

      本文标题:通过渲染UIView 生成一个新的UIImage

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