I'm using the webBrowser control and trying to capture a screen shot from it. I start up the webBrowser control and set its URL to some web page. It displays just fine. Then, in response to a button press, I capture the image of the page that's contained within the webBrowser control, like this:
Bitmap bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser.Width, webBrowser.Height));
And it does indeed get the page image and I can display it in a pictureBox control.
But a problem occurs when I click on a link in the displayed page and it goes to some other page. If I then click my "grab the page image" button, which again invokes the above code, the image that I get is completely white, even though the page is displayed properly within the webBrowser control.
If I stay on the initial web page I can repeatedly grab the image and display it. But whenever I go to some other subsequent page (which loads into the same webBrowser control) the image that gets grabbed is just plane white.
What do I have to do to get it to get the image from subsequently loaded pages?
Loading
Steve DawkinsPosted Jul 17, 2011, 4:10 PM
VulpesPosted Mar 22, 2011, 5:15 AM
As Sam said there's quite a lot of this sort of thing in the .NET Framework though sometimes you actually get a 'not supported exception' if you try to call such a method or property.
As it also says in the docs that it's 'infrastructure', I suspect they haven't done that here so that it can, if necessary, be called by MS's own developers who will know its limitations.
Sam HobbsPosted Mar 22, 2011, 2:23 AM
Something else that has caused me confusion is that sometimes WPF and Windows Forms have the same names for classes that are very different.
Roger GarrettPosted Mar 21, 2011, 8:31 PM
Roger GarrettPosted Mar 21, 2011, 8:25 PM
Sam HobbsPosted Mar 21, 2011, 8:02 PM
VulpesPosted Mar 21, 2011, 5:42 PM
Could you use the Graphics.CopyFromScreen method (http://msdn.microsoft.com/en-us/library/6yfzc507.aspx) instead ?