Reputation: 1721
I want to do a screenshot of a UIWebView, I use this code
Code:
UIGraphicsBeginImageContext(self.vistaWeb.bounds.size);
[vistaWeb.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage,nil,NULL,NULL);
and it work well, my problem is that I want to make a screenshot of all the uiwebview, not only the visible view...for example, I have a uiwebview of 200x200 but the page is 200x500, whit this code I make a screenshot of 200x200 while I want to do a screenshot of 200x500.what I have to do?
kikko088
Upvotes: 1
Views: 3818
Reputation: 2297
The problem is in the line:
UIGraphicsBeginImageContext(self.vistaWeb.bounds.size);
You are using the size of your view and not the size of its content. In order to obtain the size of your page use the following approach. Then just replace self.vistaWeb.bounds.size
with an appropriate size.
In order to support retina you should replace the first line of your code with the following:
CGSize layerSize = ...
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f) {
UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0f);
} else {
UIGraphicsBeginImageContext(layerSize);
}
Upvotes: 3