• iOS 截屏功能的实现


    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

    }

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

    {

        NSLog(@"开始截屏");

        [self cutterViewToDocument];

    }

    - (void)cutterViewToDocument

    {

             UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

        

             UIGraphicsBeginImageContext(screenWindow.frame.size);

             [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];

             UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();

            UIGraphicsEndImageContext();

        

           NSData *screenShotPNG = UIImagePNGRepresentation(screenShot);

             NSError *error = nil;

         BOOL  isSuccess=  [screenShotPNG writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"screen.png"] options:NSAtomicWrite error:&error];

        NSLog(@"%@",NSHomeDirectory());

        if (isSuccess) {

            NSLog(@"截屏成功");

        }else{

        

            NSLog(@"截屏失败");

        }

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    boundandbranch method
    图像格式PPM,PGM和PBM
    感兴趣文章
    生成数据库脚本
    安徽太和华药会总结
    正则表达式语法参考
    xml
    对项目开发有很大帮助的jquery网站
    增强 VSS 的文件共享安全性
    支付宝及时到帐接口使用详解
  • 原文地址:https://www.cnblogs.com/woaixixi/p/4635665.html
Copyright © 2020-2023  润新知