Last active
December 28, 2015 09:59
-
-
Save sag333ar/7482896 to your computer and use it in GitHub Desktop.
Take screen-shot of current-application-window.
This file contains hidden or 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
// a function to take screen-shot of application's screen | |
- (UIImage*)takeScreenshot | |
{ | |
// get the key-window references | |
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; | |
// manipulate boundries of key-window | |
CGRect rect = [keyWindow bounds]; | |
// create context using size | |
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); | |
// get the context reference | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
// render in context | |
[keyWindow.layer renderInContext:context]; | |
// get the rendered image | |
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); | |
// complete context | |
UIGraphicsEndImageContext(); | |
// return image | |
return takeScreenshot; | |
} | |
// ------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment