-(UIImage *)
snapshotScreen{
UIView *view = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image=[self snapshotScreen];
NSData *data=UIImagePNGRepresentation(image);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
NSLog(@"image:%@ imageLength:%ld",image,data.length);
}
UIView *view = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//按钮事件(开始截屏)
UIImage *image=[self snapshotScreen];
NSData *data=UIImagePNGRepresentation(image);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
NSLog(@"image:%@ imageLength:%ld",image,data.length);
}