iOS Phone screenshot main steps
1. Create a graphics context
2. Draw the screen to it
3. Save pictures to albums
4. Close the graphics context
iOS Phone screenshot specific implementation
-(ibaction)truncation:( UIButton *) Sender {
// Delay2seconds Before you take a screenshot.
Dispatch_after(Dispatch_time(Dispatch_time_now, (int64_t)(2.0 * nsec_per_sec)), Dispatch_get_main_queue(), ^{
#pragma mark created
//1.Create a graphics context that is equivalent to a canvas
Uigraphicsbeginimagecontext( Self.View.Frame.size);
//2.draw the screen to it
[ Self.View.LayerRenderincontext:Uigraphicsgetcurrentcontext()];
UIImage*newimage =Uigraphicsgetimagefromcurrentimagecontext();
//3.Save pictures to albums
Uiimagewritetosavedphotosalbum(NewImage, Self,@selector(image:didFinishSavingWithError:contextInfo:),Nil);
//4. Close the graphics context Span style= "font-family:menlo;font-size:14px;line-height:normal;" >
         uigraphicsendimagecontext ();
});
#pragma mark determine if the creation was successful----third-party library implementation available
- (void) Image: (UIImage*) Image didfinishsavingwitherror: (Nserror*) Error ContextInfo: (void*) contextinfo{
if(Error) {
//NSLog (@ "Save failed");
[Mbprogresshud ShowError:@"Save failed, Please check if your app has permission to access the album"];
}Else{
//nslog (@ "saved successfully");
[Mbprogresshud showsuccess:@"saved successfully"];
}
}
This article is from "Dream Xiang 8" blog, please be sure to keep this source http://mengxiang8.blog.51cto.com/11234654/1745379
iOS Phone screenshot