func saveToLocal() {
//截屏
let screenRect = UIScreen.mainScreen().bounds
UIGraphicsBeginImageContext(screenRect.size)
let ctx:CGContextRef = UIGraphicsGetCurrentContext()!
self.view.layer.renderInContext(ctx)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext(); //保存相册
UIImageWriteToSavedPhotosAlbum(image!, self, "image:didFinishSavingWithError:contextInfo:", nil) } func image(image:UIImage,didFinishSavingWithError error:NSError?,contextInfo:AnyObject) { if error != nil {
K12ProgressHUD.showError("保存失败", view: self.view)
} else {
K12ProgressHUD.showSucess("保存成功", view: self.view)
}
}
swift3 截屏
func getScreenImage() -> UIImage {
//截屏
let screenRect = UIScreen.main.bounds
UIGraphicsBeginImageContext(screenRect.size)
let ctx:CGContext = UIGraphicsGetCurrentContext()!
self.view.layer.render(in: ctx)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return image!
}