zoukankan      html  css  js  c++  java
  • 截图保存到相册

    
    
       // 1.截图
    
        UIImage *image = [UIImage captureWithView:self.paintView];
    
        
    
        // 2.保存到图片
    
        UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    
    /**
    
     保存图片操作之后就会调用
    
     */
    
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
    
    {
    
        if (error) { // 保存失败
    
            [MBProgressHUD showError:@"保存失败"];
    
        } else { // 保存成功
    
            [MBProgressHUD showSuccess:@"保存成功"];
    
        }
    
    }
    


    + (instancetype)captureWithView:(UIView *)view { // 1.开启上下文 UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0); // 2.将控制器view的layer渲染到上下文 [view.layer renderInContext:UIGraphicsGetCurrentContext()]; // 3.取出图片 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); // 4.结束上下文 UIGraphicsEndImageContext(); return newImage; }
  • 相关阅读:
    进程间通信
    图形的保存与重绘
    mysql记录1
    文件操作
    多线程及聊天室程序
    健康是成功之本
    文档与串行化
    HTML网页制作基础
    Hook和数据库访问
    C++基础笔记1
  • 原文地址:https://www.cnblogs.com/yinshenge/p/4560486.html
Copyright © 2011-2022 走看看