Advertisement
Guest User

Untitled

a guest
May 24th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. ###Generating a screenshot
  2.  
  3. ```objective-c
  4. - (UIImage *)screenshot
  5. {
  6. CGSize imageSize = CGSizeZero;
  7.  
  8. imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  9.  
  10. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  11. CGContextRef context = UIGraphicsGetCurrentContext();
  12. for (UIWindow *window in [[UIApplication sharedApplication] windows])
  13. {
  14. CGContextSaveGState(context);
  15. CGContextTranslateCTM(context, window.center.x, window.center.y);
  16. CGContextConcatCTM(context, window.transform);
  17. CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
  18.  
  19. if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
  20. {
  21. [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
  22. }
  23. else
  24. {
  25. [window.layer renderInContext:context];
  26. }
  27. CGContextRestoreGState(context);
  28. }
  29.  
  30. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  31. UIGraphicsEndImageContext();
  32. return image;
  33. }
  34. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement