Create a Bitmap of a webpage programmatically...how?

J

Joe Black

Hi everyone,
I have a pesky little problem that is driving me nuts.
I'm trying to capture an image of a web page programmatically in a
background thread or process.
What I'd like to do is create a Bitmap object of a webpage from, say,
the new WebBrowser control of .net 2.0 or even the old ActiveX browser
control, without opening any forms.

I tried with the new WebBrowser control, but the only thing I've managed
to do is open up a form with the control in it, and do a screen capture
of a rectangle the same size of the control.
But the problem is that I need to do it /without/ opening the Form. :(
I think I'm getting close, but I really can't find a way to do it as a
background process.

Can anyone please point me in the right direction?

Thanks
 
J

Joe Black

Thanks for your reply,
I tried with PrintWindow API, but all I get is a black bitmap if try to
capture a control that is not visible.

Here is what i do:

[DllImport("user32.dll")]
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, uint
nFlags);

//...

Bitmap bm = new Bitmap(webBrowser1.Width, this.webBrowser1.Height);
Graphics g = Graphics.FromImage(bm);
IntPtr hdc = g.GetHdc();
Form1.PrintWindow(webBrowser1.Handle, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();
g.Dispose();
this.pictureBox1.Image = bm;

//...

Am I missing something?
 
L

Lee Jackson

Hi everyone,
I have a pesky little problem that is driving me nuts.
I'm trying to capture an image of a web page programmatically in a
background thread or process.
What I'd like to do is create a Bitmap object of a webpage from, say,
the new WebBrowser control of .net 2.0 or even the old ActiveX browser
control, without opening any forms.

I tried with the new WebBrowser control, but the only thing I've managed
to do is open up a form with the control in it, and do a screen capture
of a rectangle the same size of the control.
But the problem is that I need to do it /without/ opening the Form. :(
I think I'm getting close, but I really can't find a way to do it as a
background process.

Can anyone please point me in the right direction?

Thanks

I have exactly the same requirement coming at me somewhere down the
road - if you find a solution please let us know.

Ive not given this very much thought myself yet but one idea might be
to use something like virtual print driver
http://www.print-driver.com/... I REALLY dont know if a third party
component would be requied for this but just a thought.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top