• 截取屏幕并保存到本地


     /* Capture the screenshot */
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0.0f);

        if ([self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]){
            NSLog(@"Successfully draw the screenshot.");
        } else {
            NSLog(@"Failed to draw the screenshot.");
        }
        UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        /* Save it to disk */
        NSFileManager *fileManager = [[NSFileManager alloc] init];
        NSURL *documentsFolder = [fileManager URLForDirectory:NSDocumentDirectory
                                                     inDomain:NSUserDomainMask
                                            appropriateForURL:nil
                                                       create:YES
                                                        error:nil];
        NSURL *screenshotUrl = [documentsFolder
                               URLByAppendingPathComponent:@"screenshot.png"];
        
        NSData *screenshotData = UIImagePNGRepresentation(screenshot);
        
        if ([screenshotData writeToURL:screenshotUrl atomically:YES]){
            NSLog(@"Successfully saved screenshot to %@", screenshotUrl);
        } else {
            NSLog(@"Failed to save screenshot.");
        }

  • 相关阅读:
    Postfix 邮件服务器搭建
    DER、CRT、CER、PEM格式的证书及转换
    Apache SSL 服务搭建
    scapy 中的ARP
    关于linux特殊含义的转义符33
    关于javascript中defineProperty的学习
    python QT 编程之路
    python socket编程制作后门木马(原创)
    mybatis学习——映射器(mappers)
    mybatis学习——properties属性实现引用配置文件
  • 原文地址:https://www.cnblogs.com/NSNULL/p/4629556.html
Copyright © 2020-2023  润新知