Capturing screenshot on iPhone needs the QuartzCore framework.
1. Right click the Framework folder in your Xcode project.
2. Add -< Add Existing Frameworks
3. Choose the QuartzCore.framework
4. Import the QuartzCore framework in the .h header file
#import <QuartzCore/QuartzCore.h>
5. Add the following few lines in the .m implementation file to capture the screenshot
// Capture Screenshot UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);
6. Try it
Done =)
I used this code to take the snapshot of my app running on simulator, the quality of the snap is not good, Any idea?
LikeLike
I guess you want to capture an images screenshot on iPhone. The following post should help.
StackOverflow – UIGraphicsGetImageFromCurrentImageContext gives poor quality / low resolution image, how do I get better?
LikeLike
hi,thanks for the help
my problem is is want to take the screenshot in landscape mode itself but this code give me a portrait mode screenshot.which make my screenshot hard to handle even after rotating it
CurrentScreen.transform = CGAffineTransformMakeRotation(4.71238898);
thats how i rotate my image
LikeLike
I didn’t try landscape screenshot, see if the following post help.
StackOverflow – iPhone screen shot in landscape view
LikeLike
I’m at Startup Weekend in LA right now where a few of the iPhone developers here have said that it’s impossible to take a screenshot programmatically between applications due to iOS sandbox restrictions but I’m not convinced of this. Two tutorials explain how to capture a screenshot programmatically when using a single application (see “Programmatically Getting a Screencapture of any UIView”, http://www.icodeblog.com/2009/07/27/1188/ and “iPhone – Capture Screenshot Programmatically”, https://ykyuen.wordpress.com/2010/04/10/iphone-capture-screenshot-programmatically/) but I am trying to figure out if a screenshot can be taken between one application and another like when a new text message comes in when the iPhone is not locked, and when it is.
Any help will be appreciated…thanks.
Noah
LikeLike
Hi Noah,
Do you mean you want to take a screenshot and save it to the iphone album when
1. The iPhone is unlocked
2. The iPhone is locked
3. When a sms is received
if that is the case, i think you can refer to the following Q&A for the 1st and 2nd scenarios.
StackOverflow – Lock Unlock events iphone
For the third one, i think there should be some api to detect that. you can try to search on google.
Kit
LikeLike
Thanks much for posting this.
I just put it in my application, and got a great picture of everything BUT my navigation bar.
Do you have any idea how to capture that as well?
LikeLike
Thanks for your comment. =)
If you want to capture the navigation bar, i guess the sample code in the following post may help.
Screenshots-A Legal Way To Get Screenshots
LikeLike
can we take screenshot of avplayerLayer ?
LikeLike
No idea on that but the following post may help.
StackOverflow – Get the screenshot of a streaming video on iphone
LikeLike
the code work just fine thanks.
did any one know how to Capture just half screen
LikeLike
Maybe this could help.
StackOverflow – How do you crop an image in iOS
LikeLike