美文网首页
图片处理 之 截屏

图片处理 之 截屏

作者: 小凡凡520 | 来源:发表于2019-10-08 09:22 被阅读0次
// 开启上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, 0)

// 渲染
self.view.drawHierarchy(in: self.view.bounds, afterScreenUpdates: true)

let result = UIGraphicsGetImageFromCurrentImageContext()

// 关闭上下文
UIGraphicsEndImageContext()

resultImgView.image = result
// 开启上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, 0)

guard let context = UIGraphicsGetCurrentContext() else {
    return
}

self.view.layer.render(in: context)

guard let cgImg = context.makeImage() else {
    return
}

// 关闭上下文
UIGraphicsEndImageContext()

resultImgView.image = UIImage(cgImage: cgImg)

相关文章

网友评论

      本文标题:图片处理 之 截屏

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