美文网首页
页面截图

页面截图

作者: 碎梦_aimee | 来源:发表于2018-06-25 15:04 被阅读0次

NSString *hStr = [web stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];//get the height

NSString *wtStr = [web stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"];// Get the width

        web.frame=CGRectMake(0, 0, [wtStr floatValue], [hStr floatValue]);

     UIGraphicsBeginImageContextWithOptions(web.size, NO, [UIScreen mainScreen].scale);

        CGContextRef ctx = UIGraphicsGetCurrentContext();

        [web.layer renderInContext:ctx];

        UIImage *finalimage = UIGraphicsGetImageFromCurrentImageContext();

NSData *imageViewData = UIImagePNGRepresentation(finalimage);

//保存到本地沙盒

[imageViewData writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"cutImage"] atomically:YES];

 UIGraphicsEndImageContext();

相关文章

网友评论

      本文标题:页面截图

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