Skip to content

Instantly share code, notes, and snippets.

@Geri-Borbas
Created October 8, 2013 14:17
Show Gist options
  • Save Geri-Borbas/6885413 to your computer and use it in GitHub Desktop.
Save Geri-Borbas/6885413 to your computer and use it in GitHub Desktop.
Three way to create UIView snapshot containing SpriteKit content.
-(UIImage*)snapshotUsingPrivateApi
{
// Works fine, but private.
CGImageRef snapshot = UIGetScreenImage();
UIImage *snapshotImage = [UIImage imageWithCGImage:snapshot];
return snapshotImage;
}
-(UIImage*)snapshotUsingDrawHierarchy
{
// Captures SpriteKit content!
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshotImage;
}
-(UIImage*)snapshotUsingLayer
{
// Captures UIKit content only.
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshotImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment