zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    推荐:负采样
    JNDI学习总结(一)——JNDI数据源的配置
    前端性能优化
    java中的引用类型概念
    java中的各种数据类型在内存中存储的方式
    POI导出EXCEL经典实现
    synchronized 与 Lock 的那点事
    黑马程序员_Map<K,V> 映射关系 Map.Entry
    Java ConcurrentModificationException异常问题
    表 (list)
  • 原文地址:https://www.cnblogs.com/woaixixi/p/4635665.html
Copyright © 2011-2022 走看看