How to capture image from WebBrowser control?



Hello all,

I need to develop a small application that browses webpages
automatically and saves the images found on those pages. Probably you
would say: iterate the HtmlElements collection, find the value of the
SRC attribute, load each image using its corresponding URL and then
save it.

That doesn't work unfortunately, because the images are generated
dynamically when requesting the webpage.

What I did is the following:
- Browse to the desired webpage in a WebBrowser control
- Hide all elements except the desired image
- Resize the WebBrowser to display the full image

I can't manage to capture the displayed image from the WebBrowser
control. My WebBrowser control is named wbBrowser

What I tried is the following:

Graphics g = wbBrowser.CreateGraphics();
Bitmap bmp = new Bitmap(width, height);
g.DrawImage(bmp, 1, 1, width, height);
bmp.Save("C:\\test_file.jpg",System.Drawing.Imaging.ImageFormat.get_Jpeg());
g.Dispose();

It does save the file, but it is completely blank. Its background color
is black and I see nothing of the 'captured' image in it. I also tried
to save as bitmap. It saves the file, also completely blank, but with a
grey background color.

File size is 9KB using either JPG or BMP format.

What am I doing wrong here?

If I'm correct, it should be possible to capture the displayed contents
of the WebBrowser control as a bitmap and save that to a file.

Any help would be greatly appreciated.

Thank you all very much in advance!

Regards,

Alex

.



Relevant Pages

  • WebBrowser (loop automation)
    ... tasks on the webpage. ... Uri myUri = new Uri; ... Then for the webbrowser control I have the following method: ... I wrote the following code to perfom a loop (hoping to call sereval times ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Urgent: Integrate WebBrowser Control in ASP.NET/VB.NET?
    ... WebRequest/WebResponse to capture the actual HTML of the page (otherwise ... The WebBrowser control is really more for WinForms and displaying HTML and ... Kyril ...
    (microsoft.public.dotnet.framework.aspnet)
  • Communicating Between VB6 and a HTML Document
    ... WebBrowser control from within a Visual Basic project. ... I then created a webpage called Page1.html, ... Launching the page via running the VB project will cause the webpage textbox ...
    (microsoft.public.scripting.vbscript)
  • Re: How to capture image from WebBrowser control?
    ... bstrPrinterName, IntPtr hDC); ... Browse to the desired webpage in a WebBrowser control ... I can't manage to capture the displayed image from the WebBrowser ...
    (microsoft.public.dotnet.framework.drawing)
  • RE: Capture WebPage as any Image format
    ... thing, "DrawToBitmap" method is not from WebBroswer class, but from ... We are working in a web application and we wanted to capture the full ... webpage into an image file. ...
    (microsoft.public.dotnet.languages.csharp)