iOS手机截屏使用

时间:2021-05-16 19:02:44
.截屏 保存 。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"]; 。使用 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];