How to take a screenshot programmatically?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
UIGraphicsBeginImageContextfor this purpose.For example :
Here
1. First i take the image context, i’ve given it as
myViewwhich is a webview, you can give whatever you wish for. This takes the image of webview that can be seen on the screen.2 Using
UIGraphicsGetImageFromCurrentImageContext()i convert the screenshot of my webview into an image.3. By using
UIGraphicsEndImageContext()i ask it end the context.4. I’m saving the image into an
NSDatabecause i had to mail the screenshot. And keep it inNSDataseemed a good option if it is used to send or save.EDIT: To add it to the camera roll you need to write:
UIImageWriteToSavedPhotosAlbum(theImage,nil,NULL,NULL);afterUIGraphicsEndImageContext();