Last active
December 17, 2015 18:49
-
-
Save Kursulla/5656006 to your computer and use it in GitHub Desktop.
Create screenshot in iOS. [Objective-C,ios,xcode]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size; | |
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); | |
CGContextRef ctx = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4*(int)screenSize.width, colorSpaceRef, kCGImageAlphaPremultipliedLast); | |
CGContextTranslateCTM(ctx, 0.0, screenSize.height); | |
CGContextScaleCTM(ctx, 1.0, -1.0); | |
[(CALayer*)self.view.layer renderInContext:ctx]; | |
CGImageRef cgImage = CGBitmapContextCreateImage(ctx); | |
UIImage *image = [UIImage imageWithCGImage:cgImage]; | |
CGImageRelease(cgImage); | |
CGContextRelease(ctx); | |
//UIImage *image can be used for saving for file, or to be placed in some UIImageView or wathever... | |
[UIImageJPEGRepresentation(image, 1.0) writeToFile:@"screen.jpg" atomically:NO]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment