Welcome Guest Search | Active Topics | Sign In | Register

WebView Capture() size is not the same of WebView size Options
Juliana
Posted: Wednesday, May 2, 2018 12:29:53 PM
Rank: Newbie
Groups: Member

Joined: 4/27/2018
Posts: 1
Hey everyone!
I'm trying to capture a web page. I implemented the WebView_LoadCompleted to wait the page to capture the image, but sometimes the image does not load completely on the web page. I debugged the program and I realise that there's a point that the webview loads, but the webview.capture() does not capture the entire page. The first test always works, but then if I made another request it returns with this problem.



private static void WebView_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
var browser = sender as WebView;
if (browser == null || browser.Url == null) return;


browser.Resize(new Size(browser.GetPageSize().Width, browser.GetPageSize().Height));
var size = browser.Capture().Size; //I've set this variable to see the capture size and realised that at one point it's not capturing the entire web page.

using (var img = browser.Capture())
{
using (var stream = new MemoryStream())
{
img.Save(stream, ImageFormat.Png);
byte[] bytes = stream.ToArray();
PictureBytes = bytes;
}
}
eo_support
Posted: Wednesday, May 2, 2018 3:18:42 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

You should not resize the browser to page size. This will fail sometimes if the page is too large, or when you call it multiple times (as you have noticed). This is because a capture allocates memory from video buffer (sometime directly off the video card's memory) and the video buffer is primary designed for displaying images on screen and a video card driver's memory management may reject such allocation even if it has enough memory because the requested buffer size is not "reasonable" compare to the screen size. So if you try to capture anything that is significantly bigger than the screen, you can run into problem.

One way you can use to avoid such issue is to make a serials of captures with different offset (by passing different Top value to the srcRect argument). You can then merge them together to form a big image if you have to. Make sure you use the latest build for this because earlier version can only capture visible area.

Also you should not do capture directly from inside LoadCompleted event. You can use BeginInvoke to delay the execution until the LoadCompleted event handler returns.

Hope this helps. Please feel free to let us know if you have any questions.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.