美文网首页
iOS 保存截图到相册(高清)

iOS 保存截图到相册(高清)

作者: WS_0909 | 来源:发表于2018-10-30 15:09 被阅读0次
    - (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(@"截屏以保存至系统相册");
    }
    

    相关文章

      网友评论

          本文标题:iOS 保存截图到相册(高清)

          本文链接:https://www.haomeiwen.com/subject/kzhyjftx.html