Welcome Guest Search | Active Topics | Sign In | Register

WebView - Create and Capture Image Options
eo_support
Posted: Wednesday, September 10, 2014 7:41:21 AM
Rank: Administration
Groups: Administration

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

What is your EO.WebBrowser.dll version number?

Thanks!
Matjaz
Posted: Wednesday, September 10, 2014 7:50:06 AM
Rank: Member
Groups: Member

Joined: 8/10/2014
Posts: 15
Hi,

DLL version is 3.0.79.0

Matjaž

eo_support
Posted: Wednesday, September 10, 2014 9:05:55 AM
Rank: Administration
Groups: Administration

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

Please try to download it from our download page again. I believe this was an issue for build 3.0.79 but was fixed in the current build (EO.Total 2014.0.14, EO.WebBrowser 3.0.80).

Thanks!
BenjaminSimpson1989
Posted: Tuesday, February 17, 2015 1:38:22 PM
Rank: Advanced Member
Groups: Member

Joined: 1/12/2015
Posts: 81
The following code does not resize the webview completely:
Code: Visual Basic.NET
wbView = New WebView
        wbView.Create(IntPtr.Zero)
        wbView.LoadUrlAndWait("http://www.ebay.com/sch/iPads-Tablets-eBook-Readers-/171485/i.html")
        Dim s As Size = wbView.GetPageSize
        wbView.Resize(s.Width, s.Height)
        wbView.Capture().Save("c:\temp\snap.bmp")


Sometimes if I try it a few times in a row it will work. Also, which image formats can you save to with the Save method?
eo_support
Posted: Tuesday, February 17, 2015 1:59:58 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi benpm,

Resize is asynchronous. You can call WebView.DoEvents() with a small value to wait for it to complete. For example, WebView.DoEvents(200).

Capture returns a standard .NET System.Drawing.Image object to you. Save method is a method of the Image class and it is implemented by .NET, not by us. So you will need to consult other resources as to what format it supports.

Thanks!
BenjaminSimpson1989
Posted: Tuesday, February 17, 2015 4:32:47 PM
Rank: Advanced Member
Groups: Member

Joined: 1/12/2015
Posts: 81
Adding WebView.DoEvents() worked. Thanks.
BenjaminSimpson1989
Posted: Monday, May 23, 2016 4:51:48 PM
Rank: Advanced Member
Groups: Member

Joined: 1/12/2015
Posts: 81
I'm using the version: 16.0.91.0 of EO.WebBrowser. The following code does not resize the webview at all:
Code: C#
ThreadRunner threadRunner = new ThreadRunner("ThreadRunner");

            WebView wb = threadRunner.CreateWebView();

            threadRunner.Send(() =>
            {
                var nav = wb.LoadHtml(html, url.ToString());
                nav.WaitOne();
                Size s = wb.GetPageSize();
                wb.Resize(s.Width, s.Height);
                
                for (var i = 0; i < 10; i++)
                {
                    WebView.DoEvents(200 * (i + 1));
                    Image img = wb.Capture();
                    if (img.Width == s.Width || img.Height == s.Height || (img.Width >= s.Width * .9 && img.Height >= s.Height * .9))
                    {
                        bmSnapshot = new Bitmap(img);
                        break;
                    }
                }
            });
eo_support
Posted: Tuesday, May 24, 2016 5:34:59 PM
Rank: Administration
Groups: Administration

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

We have confirmed this to be a bug. This will be fixed in our next build. We will reply again as soon as the new build is posted.

Thanks!
eo_support
Posted: Friday, May 27, 2016 5:37:42 PM
Rank: Administration
Groups: Administration

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

This is just to let you know that we have posted a new build that should fix this problem. You can download the new build from our download page.

Thanks!
BenjaminSimpson1989
Posted: Monday, June 20, 2016 12:13:21 PM
Rank: Advanced Member
Groups: Member

Joined: 1/12/2015
Posts: 81
The following code is using a picturebox as the handle for the webview. And ExecuteJS is running some Javascript which hides some of the HTML elements on the page so the image looks cleaner.

Code: C#
void WaitForBrowserAndLoadBitmap(WebView wb, NavigationTask nav)
        {
            nav.WaitOne();

            ExecuteJS(wb);

            PictureBox pb = (PictureBox)this.Controls.Find("pb", false)[0];
            Size s = wb.GetPageSize();
            pb.Size = s;
            pb.Refresh();

            //force thread to sleep in order to allow UI to resize
            Image img;
            int sizeHasntChangedCount = 0;
            int prevWidth = -1;
            int prevHeight = -1;
            do
            {
                Thread.Sleep(200);
                img = wb.Capture();
                s = wb.GetPageSize();

                if (img != null && s.Width == prevWidth && s.Height == prevHeight)
                {
                    sizeHasntChangedCount += 1;
                }
                else
                {
                    prevWidth = s.Width;
                    prevHeight = s.Height;
                    sizeHasntChangedCount = 0;
                }
            } while (!(img != null && img.Width >= s.Width - 10 && img.Height >= s.Height - 10) && sizeHasntChangedCount < 5);

            bmSnapshot = new Bitmap(img);
        }


Everything is normally working fine. But I've found that under a heavy CPU and memory usage, "wb.Capture()" is always returning null. Is there a timeout to capture the image? Can this be increased?
BenjaminSimpson1989
Posted: Monday, June 20, 2016 12:22:53 PM
Rank: Advanced Member
Groups: Member

Joined: 1/12/2015
Posts: 81
I just did some more testing. When I change the "wb.capture()" to "wb.Capture(new Rectangle(0, 0, 1000, 3000))", it works. However, the actual size the image should be is: 1000x30998
eo_support
Posted: Wednesday, June 29, 2016 2:21:01 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
benpm wrote:
I just did some more testing. When I change the "wb.capture()" to "wb.Capture(new Rectangle(0, 0, 1000, 3000))", it works. However, the actual size the image should be is: 1000x30998


Hi,

We have looked into this and you can't capture images of such huge size. Capturing an image of that size requires a huge screen buffer which often can not be allocated. When the screen buffer allocation fails, Capture will return null. The work around for this is to either scale the output image by providing a destSize argument to the Capture method, or call Capture multiple times so that you get multiple smaller images. You can then merge them into a single big image if desired --- keep in mind you may still run into out of memory error on the merging step.

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.