页面截图
2018-06-25 本文已影响0人
碎梦_aimee
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();