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

  • 相关阅读:
    鼠标移向小图显示大图
    一个简单漂亮的CSS相册代码
    windows 应该关闭服务
    NetBIOS名称
    DOS命令大全(经典收藏)
    大揭露:Win中也有各种不老实的服务
    变量名
    ASP.NET2.0 GridView小技巧汇粹 (转)
    Dfs实战技术
    windows 2003中活动目录支持文件
  • 原文地址:https://www.cnblogs.com/woaixixi/p/4635665.html
Copyright © 2011-2022 走看看