Happened to think of screenshots, so I went to the old code, and the method of online verification, cookie-cutter bar, do a sorting and summary
1. Save pictures to album:
// The image can be local or network image, The needs of the network through the SD transformation UIImageWriteToSavedPhotosAlbum (self. ImageView. Image, the self, @selector(image:didFinishSavingWithError:contextInfo:), nil); - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ if (error == Nil) {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" prompt "message:@" saved in phone album" delegate:self CancelButtonTitle :nil otherButtonTitles:@" confirm ", nil]; [alert show]; }else{UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" message:@" save failed "Delegate :self cancelButtonTitle:nil OtherButtonTitles :@" confirm ", nil]; [alert show]; }}Copy the code
2. Save the screenshot
This is a method with a block that allows you to get a callback after a successful failure to save a screenshot to do something. And the selector method here is the same as the one above, which is an extension of the last method, Set to save the size of the region / * * * simple screenshot and save the picture the local * / - (void) makeScreenShotCompletion: void (^) (UIImage * image)) completion open context {/ / < span style="font-family: Arial, Helvetica, sans-serif;" < / span > > Settings screen size UIGraphicsBeginImageContext (self. View. Bounds. The size). [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; / / get photo UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); / / close the context UIGraphicsEndImageContext (); completion(image); / * * * to save image to the local album * / UIImageWriteToSavedPhotosAlbum (image, the self, @selector(image:didFinishSavingWithError:contextInfo:), nil); // Save the image to the photo library}Copy the code
Demo download address: Click download