Created
September 12, 2017 03:55
-
-
Save junyixin/6772119caf9844aaa7964031ca0f8a13 to your computer and use it in GitHub Desktop.
iOS截图并保存(Objective-C)
This file contains 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
- (void)saveImageToPhotos:(UIImage *)image { | |
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:),nil); | |
} | |
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { | |
if (error == nil) { | |
NSLog(@"保存成功"); | |
} else { | |
NSLog(@"失败"); | |
} | |
} | |
- (UIImage *)snipImage { | |
UIGraphicsBeginImageContext(self.view.frame.size); | |
CGContextRef contextRef = UIGraphicsGetCurrentContext(); | |
[self.view.layer renderInContext:contextRef]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment