美文网首页
iOS 截屏

iOS 截屏

作者: 何大叔 | 来源:发表于2019-02-27 11:05 被阅读0次

    截取屏幕并保存本地

    1. 截图

    - (UIImage*)createImageWithView:(UIView*)view{

       CGSize s = view.bounds.size;

        UIGraphicsBeginImageContextWithOptions(s, YES,[UIScreen mainScreen].scale);

        [viewdrawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

        UIImage*image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        returnimage;

    }

    2.保存到相册

    - (void)saveImageToAlbum{

        UIImage* image = [selfcreateImageWithView:self.webView];

    UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), (__bridgevoid*)self);

    }

    - (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo

    {

        if(!error){

           // NSLog(@"保存成功");

            [self.viewmakeToast:@"保存成功"];

        }else{

             [self.viewmakeToast:@"保存失败"];

             NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);

        }

    }

    相关文章

      网友评论

          本文标题:iOS 截屏

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