1.设定截图的区域
UIGraphicsBeginImageContextWithOptions(size:CGSize, opaque: Bool, scale: CGFloat)
2.获取当前截图的上下文
let contextRef = UIGraphicsGetCurrentContext()
3.建立联系
self.layer.renderInContext(contextRef!) /*self 为UIView*/
4.获取图片从当前图片上下文
let img = UIGraphicsGetImageFromCurrentImageContext()
5.保存图片
UIImageWriteToSavedPhotosAlbum(image: UIImage, completionTarget: AnyObject, completionSelector: Selector, contextInfo: UnsafeMutablePointer)
selector 方法为以下且必须实现
Swift:
func image(image:UIImage,didFinishSavingWithError:NSError,contextInfo:UnsafePointer)
Objective-C:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
网友评论