Welcome Guest Search | Active Topics | Sign In | Register

Wrong content while Capture in WebView after scrolling the page Options
ozheek
Posted: Friday, September 30, 2016 7:14:18 PM
Rank: Advanced Member
Groups: Member

Joined: 8/29/2016
Posts: 64
If I am trying to capture the picture with specific size and position,
it doesn't work.

This bug appear only on some sites and to see it you need to scroll the page first.
After it scrolled you won't get new content, you will see old content (before scrolling).

If you use:
var capture = view2.Capture();
instead of
var capture = view.Capture(new System.Drawing.Rectangle(0, 0, 1000, 1000));

it works correctly.

Code: C#
Task.Run(() =>
            {
                ThreadRunner runner = new ThreadRunner();
                WebView view = runner.CreateWebView();
                view.Resize(1000,1000);
                object image = runner.Send((WebView view2, object args) =>
                {
                    NavigationTask loadTask = view2.LoadUrl("https://mouseflow.com/demo/");
                    if (loadTask.WaitOne(60000))
                    {
                        //view2.Resize(1000, view.GetPageSize().Height);
                        view.SetScrollOffset(0, 1000);
                        //Thread.Sleep(1000);
                        view.GetContentAreaSize();
                        // Doesn't get the correct image from the WebView, page is scrolled but 
                        // content is other
                        var capture = view2.Capture(new System.Drawing.Rectangle(0, 0, 1000, 1000));
                        // Works okay
                        //var capture = view2.Capture();
                        return capture;
                    }
                    return null;
                }, view, null);

                ((System.Drawing.Image)image).Save("D:\\ppp.png");
            });
eo_support
Posted: Friday, September 30, 2016 9:34:04 PM
Rank: Administration
Groups: Administration

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

This behavior is by design. When you use Capture(rect), the rect you specified is the absolute rectangle of page, which is independent of the current scrolling position. If you want the capture to start from the current scrolling position, you can add that to your rect's offset. This is exactly what WebView.Capture() does.

Thanks!
ozheek
Posted: Saturday, October 1, 2016 6:22:03 AM
Rank: Advanced Member
Groups: Member

Joined: 8/29/2016
Posts: 64
Thank you for the answer. I was using other components before and it was capturing visible area only.

Your idea I like better! :)
eo_support
Posted: Monday, October 3, 2016 8:43:38 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Great. Glad to hear that you like it!


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.