- (void)loadImageFinished:(UIImage *)image
{
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
}
//截图功能
-(UIImage *)captureImageFromView:(UIView *)view
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGRect rect = [keyWindow bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshotImage;
}
- (IBAction)savePhotoButton:(UIButton *)sender {
[self loadImageFinished:[self captureImageFromView:self.view]];
kShowD(@"截屏以保存至系统相册");
}
转载于:https://www.cnblogs.com/Ewenblog/p/10783702.html
iOS截图保存至相册
本文介绍了一个简单的iOS应用功能,实现从当前视图截图并保存到设备相册的方法。通过使用UIKit框架中的UIGraphicsBeginImageContextWithOptions和UIImageWriteToSavedPhotosAlbum函数,实现了截图并保存的功能。
6328

被折叠的 条评论
为什么被折叠?



