Reputation: 1195
I try to export web pages to image in order to share it to some social network which not allow to input too many words. When I try to render the layer of scrollview of UIWebview to the current context and create a image, just snap the visible rect of the page. How can I do it? Thank your very much!
Upvotes: 0
Views: 355
Reputation: 2822
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();
try setting the webviews height and width according to the pages width and height and then take the screenshot
Upvotes: 1
Reputation: 146
you may try this way
UIGraphicsBeginImageContext(CGSizeMake(yourwebview.frame.size.width,yourwebview.frame.size.height));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[yourwebview.layer renderInContext:ctx];
finalimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Upvotes: 0