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(@"保存完成");
    }
    
  • 相关阅读:
    无言
    计算机网络的所有课件
    Linux 分区
    Linux 文件管理权限
    DropDownList 控件
    CssClass初步语法了解
    BulletedList用途
    BulletedList项目控件基础CSS基础
    Checkbox与foreach循环
    RadioButton控件
  • 原文地址:https://www.cnblogs.com/110-913-1025/p/9261657.html
Copyright © 2011-2022 走看看