0

我尝试将网页导出为图像,以便将其分享到一些不允许输入太多单词的社交网络。当我尝试将 UIWebview 的滚动视图层渲染到当前上下文并创建图像时,只需捕捉页面的可见矩形。我该怎么做?非常感谢您!

4

2 回答 2

1
 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]);
        UIGraphicsBeginImageContext(CGSizeMake(web.frame.size.width,web.frame.size.height));
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [web.layer renderInContext:ctx];
        UIImage *finalimage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

尝试根据页面宽度和高度设置webviews的高度和宽度,然后截图

于 2012-05-02T07:21:00.923 回答
0

你可以试试这种方式

UIGraphicsBeginImageContext(CGSizeMake(yourwebview.frame.size.width,yourwebview.frame.size.height));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[yourwebview.layer renderInContext:ctx];
finalimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
于 2012-05-02T06:40:01.943 回答