iOS手机截屏使用

1.截屏 保存 。data 

//登录成功进行截屏
            //截取屏幕大小
            UIGraphicsBeginImageContext([[UIScreen mainScreen]bounds].size);
            
            [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
            
            UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
            
            UIGraphicsEndImageContext();
            
            NSData * imgdata = UIImagePNGRepresentation(image);
            if (!imgdata) {
                
                imgdata = UIImageJPEGRepresentation(image, 1.0);
            }
            
            [[NSUserDefaults standardUserDefaults]setObject:imgdata forKey:@"loginImage"];
            


2。使用

 NSData * data = [[NSUserDefaults standardUserDefaults] objectForKey:@"loginImage"];
    UIImage * image = [UIImage imageWithData:data];
    UIImageView * imageview = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageview.image = image;
    imageview.alpha = 0.6;
    [self.view addSubview:imageview];

 

posted @ 2017-03-14 15:48  徐家汇  阅读(166)  评论(0编辑  收藏  举报