zoukankan      html  css  js  c++  java
  • 保存视图的截图方法

    记录一下:

    - (void)save
    {
        //把图片保存到系统相册
        //把UIView上面的绘制的内容生成一张图片.保存.
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        //把画板上的东西绘制到上下文当中
        [self.view.layer renderInContext:ctx];
        //从上下文当中生成一张图片
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        //关闭上下文
        UIGraphicsEndImageContext();
        //把生成的图片保存到系统相册
        //注意:保存图片成功必须得要调用下面方法.
        //    image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
        UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError: contextInfo:), nil);
    }
    
    //保存图片成功时调用
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *) contextInfo
    {    
        NSLog(@"保存完成");
    }
    
  • 相关阅读:
    JS防抖和节流
    移动端屏幕适配
    vue、react对比
    HTTP缓存
    程序员必备技术网站
    W3C标准、表现与数据分离、web语义化
    VUE的响应式原理
    react更新渲染及渲染原理
    ubuntu下mysql的环境搭建及使用
    apktool反编译工具
  • 原文地址:https://www.cnblogs.com/110-913-1025/p/9261657.html
Copyright © 2011-2022 走看看