zoukankan      html  css  js  c++  java
  • 截屏到相册

    //1.创建按钮

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 50, 50)];

        [button setTitle:@"截屏" forState:UIControlStateNormal];

        [button addTarget:self action:@selector(tap:) forControlEvents:UIControlEventTouchUpInside];

        button.backgroundColor = [UIColor redColor];

        [self.view addSubview:button];

     //2.按钮点击事件    

    - (void)tap:(UIButton *)sender{

        // 1.截取全屏

            //上下文大小

        UIGraphicsBeginImageContext(self.view.bounds.size);

            //获取上下文

        CGContextRef context = UIGraphicsGetCurrentContext();

            //渲染 实时绘图

        [self.view.layer renderInContext:context];

            //取出图片

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

            //关闭上下文

        UIGraphicsEndImageContext();

        

            // 把图片保存到相册

        UIImageWriteToSavedPhotosAlbum(image,nil, nil, nil);

        

    }

    效果图

  • 相关阅读:
    HTML
    HTML
    HTML
    HTML
    HTML
    HTML
    HTML
    TOMCAT-IDEA远程debug方法
    调整mysql数据库最大连接数
    win10开机时内存使用率达到99%以上
  • 原文地址:https://www.cnblogs.com/fanwenzheIOS/p/4942542.html
Copyright © 2011-2022 走看看