iOS截图保存操作

作者: luowanglin | 来源:发表于2016-03-17 12:34 被阅读415次

    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;

    相关文章

      网友评论

        本文标题:iOS截图保存操作

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