您好,欢迎来到花图问答。
搜索
您的当前位置:首页iOS截图保存操作

iOS截图保存操作

来源:花图问答

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;

Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务