swift3.0 屏幕截圖而且保存到本地相冊

所要截取的對象swift

var bg_view: UIView!

截取而且保存的代碼以下對象

UIGraphicsBeginImageContextWithOptions(bg_view.frame.size, false, UIScreen.main.scale)
bg_view.layer.render(in: UIGraphicsGetCurrentContext()!)
        
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
        
UIImageWriteToSavedPhotosAlbum(image!,self,#selector(image(_:didFinishSavingWithError:contextInfo:)), nil)

結束!blog

相關文章
相關標籤/搜索