美文网首页
iOS 网页截屏

iOS 网页截屏

作者: Devin_明 | 来源:发表于2019-03-21 10:57 被阅读0次

#pragma mark--截屏处理

//截屏处理

- (UIImage*)cutPic{

 CGRectsnapshotFrame = CGRectMake(0, 0, _webView.scrollView.contentSize.width, _webView.scrollView.contentSize.height);

UIEdgeInsetssnapshotEdgeInsets = UIEdgeInsetsZero;

 UIImage*shareImage = [selfsnapshotViewFromRect:snapshotFrame withCapInsets:snapshotEdgeInsets];

 returnshareImage;

}

// 网页长截图

- (UIImage*)snapshotViewFromRect:(CGRect)rect withCapInsets:(UIEdgeInsets)capInsets {

 CGFloatscale = [UIScreenmainScreen].scale;

 CGSizeboundsSize = self.webView.bounds.size;

 CGFloatboundsWidth = boundsSize.width;

 CGFloatboundsHeight = boundsSize.height;

 CGSizecontentSize = self.webView.scrollView.contentSize;

 CGFloatcontentHeight = contentSize.height;

 //    CGFloat contentWidth = contentSize.width;

 CGPointoffset = self.webView.scrollView.contentOffset;

    [self.webView.scrollViewsetContentOffset:CGPointMake(0, 0)];

 NSMutableArray*images = [NSMutableArrayarray];

 while(contentHeight > 0) {

 UIGraphicsBeginImageContextWithOptions(boundsSize, NO, [UIScreenmainScreen].scale);

        [self.webView.layerrenderInContext:UIGraphicsGetCurrentContext()];

 UIImage*image = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

[images addObject:image];

 CGFloatoffsetY = self.webView.scrollView.contentOffset.y;

        [self.webView.scrollViewsetContentOffset:CGPointMake(0, offsetY + boundsHeight)];

        contentHeight -= boundsHeight;

    }

    [self.webView.scrollViewsetContentOffset:offset];

 CGSizeimageSize = CGSizeMake(contentSize.width* scale,

                                  contentSize.height* scale);

 UIGraphicsBeginImageContext(imageSize);

[images enumerateObjectsUsingBlock:^(UIImage*image, NSUIntegeridx, BOOL*stop) {

[image drawInRect:CGRectMake(0,

                                     scale * boundsHeight * idx,

                                     scale * boundsWidth,

                                     scale * boundsHeight)];

    }];

 UIImage*fullImage = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

 UIImageView* snapshotView = [[UIImageViewalloc]initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];

    snapshotView.image= [fullImage resizableImageWithCapInsets:capInsets];

 NSData*data = UIImageJPEGRepresentation(snapshotView.image, 0.3);

 return[UIImageimageWithData:data];

}

相关文章

  • iOS 网页截屏

    #pragma mark--截屏处理 //截屏处理 - (UIImage*)cutPic{ CGRectsnaps...

  • flutter:截屏

    1.flutter-截屏组件 2.flutter-截屏插件 3.flutter-iOS原生截屏 iOS代码 4.获...

  • (最新)iOS截屏

    ios webview 截屏:ios截屏 前言:介绍一下截屏有很多种做法1:截当前屏幕内容2:截整个视图的所有内容...

  • ios截屏

    ios截屏

  • Android之WebView网页滚动截图

    WebView 网页滚动截屏,可对整个网页进行截屏而不是仅当前屏幕哦!注意若Web页面存在position:fix...

  • iOS 应用内截屏分享

    需求:捕获用户截屏操作,并建议用户截屏后的操作。虽然iOS11 有系统的截屏,但 APP 内截屏可便捷操作。 封装...

  • Oneshot App:一款具有「高亮截屏中任意文字」且拥有「分

    「Oneshot」作为一款iOS App,具有 高亮截屏中文字, 同时显示文字中相关网页和 分享功能的App。对于...

  • iOS 截屏&长截屏

    截屏在 iOS 开发中经常用到,本篇文章讲的是监听用户截屏操作,并且获取截屏图片,如果当前是UIScrollVie...

  • Python爬虫学习第一课作业

    一个网页,包含div和ul,li等标签,css用的是现成的. 成果截屏 代码截屏

  • iOS屏幕截图功能

    iOS7.0之前的系统,可以通过以下代码实现截屏功能。 iOS7.0之后,系统中封装了截屏的方法- (UIView...

网友评论

      本文标题:iOS 网页截屏

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