Skip to content

Instantly share code, notes, and snippets.

@junyixin
Created September 12, 2017 03:55
Show Gist options
  • Save junyixin/6772119caf9844aaa7964031ca0f8a13 to your computer and use it in GitHub Desktop.
Save junyixin/6772119caf9844aaa7964031ca0f8a13 to your computer and use it in GitHub Desktop.
iOS截图并保存(Objective-C)
- (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