Thumbnail of WebBrowser content

P

Prosperz

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the WebBrowser
control).

How can I do to make these kind of thumbnails ?

A+
 
P

Piotr Dobrowolski

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?
[PD] Theoretically you can try to play with WM_PRINT or WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy it to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will cover it
the capture will be corupt.
 
P

Prosperz

I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

Piotr Dobrowolski said:
Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?
[PD] Theoretically you can try to play with WM_PRINT or WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy it to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will cover it
the capture will be corupt.
 
P

Piotr Dobrowolski

I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

Piotr Dobrowolski said:
Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?
[PD] Theoretically you can try to play with WM_PRINT or WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will cover
it
the capture will be corupt.
[PD] WM_PRINT is a windows message - you can send it to a window to ask it
to draw it's contents on the provided device context (hdc). You can create
hdc (i.e. by calling GetHdc of your Graphics class instance) and pass it
as a parameter to SendMessage, so that window will draw on your graphics.
Look hier for sample code (I have just found it so don't know if it works
but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/
 
P

Prosperz

More generally, is there an opensource control that made this functionality
?

I found : websnapshot and dypswebcapture but you must paid to use them.

Any tools ?


Piotr Dobrowolski said:
I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

Piotr Dobrowolski said:
Dnia 29-03-2006 o 19:18:40 Prosperz <[email protected]>
napisa³:

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?

[PD] Theoretically you can try to play with WM_PRINT or WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will cover
it
the capture will be corupt.
[PD] WM_PRINT is a windows message - you can send it to a window to ask it
to draw it's contents on the provided device context (hdc). You can create
hdc (i.e. by calling GetHdc of your Graphics class instance) and pass it
as a parameter to SendMessage, so that window will draw on your graphics.
Look hier for sample code (I have just found it so don't know if it works
but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/
 
P

Prosperz

I try the two methods, but it doesn't give me entire satisfaction.

I really would like to reproduce behavior of DrawToBitmap for a WebBrowser
Control...

How can I do that ?


Prosperz said:
More generally, is there an opensource control that made this
functionality ?

I found : websnapshot and dypswebcapture but you must paid to use them.

Any tools ?


Piotr Dobrowolski said:
I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire
web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 19:18:40 Prosperz <[email protected]>
napisa³:

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?

[PD] Theoretically you can try to play with WM_PRINT or WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much
simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will cover
it
the capture will be corupt.
[PD] WM_PRINT is a windows message - you can send it to a window to ask
it to draw it's contents on the provided device context (hdc). You can
create hdc (i.e. by calling GetHdc of your Graphics class instance) and
pass it as a parameter to SendMessage, so that window will draw on your
graphics. Look hier for sample code (I have just found it so don't know
if it works but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/
 
P

Piotr Dobrowolski

I try the two methods, but it doesn't give me entire satisfaction.

I really would like to reproduce behavior of DrawToBitmap for a
WebBrowser
Control...

How can I do that ?


"Prosperz" <[email protected]> a écrit dans le message de
[email protected]...
More generally, is there an opensource control that made this
functionality ?

I found : websnapshot and dypswebcapture but you must paid to use them.

Any tools ?


Piotr Dobrowolski said:
Dnia 29-03-2006 o 20:32:46 Prosperz <[email protected]>
napisal:

I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire
web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans
le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 19:18:40 Prosperz <[email protected]>
napisa³:

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?

[PD] Theoretically you can try to play with WM_PRINT or
WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy
it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much
simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will
cover
it
the capture will be corupt.

[PD] WM_PRINT is a windows message - you can send it to a window to ask
it to draw it's contents on the provided device context (hdc). You can
create hdc (i.e. by calling GetHdc of your Graphics class instance) and
pass it as a parameter to SendMessage, so that window will draw on your
graphics. Look hier for sample code (I have just found it so don't know
if it works but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/

[PD] Can you describe what problems do you have with solutions I have
posted above? The second one looks like it should work (I haven't tested
it but the code looks OK).
 
P

Prosperz

The second method generate an cast exception on IHTMLElementRender render =
(IHTMLElementRender) element;
Moreover, it is not based on WebBrowser Control within framework 2.0.

The first method doesn't work. It seems WebBrowser doesn't managed
WM_PRINT...

Piotr Dobrowolski said:
I try the two methods, but it doesn't give me entire satisfaction.

I really would like to reproduce behavior of DrawToBitmap for a
WebBrowser
Control...

How can I do that ?


"Prosperz" <[email protected]> a écrit dans le message de
[email protected]...
More generally, is there an opensource control that made this
functionality ?

I found : websnapshot and dypswebcapture but you must paid to use them.

Any tools ?


"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 20:32:46 Prosperz <[email protected]>
napisal:

I never used WM_PRINT and I don't know how to use it. Can you be more
precise ?

I would like to precise that I want to make a screenshot of an entire
web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans
le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 19:18:40 Prosperz <[email protected]>
napisa³:

Hi,

I would like to make thumbnails of web page by capture content of a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?

[PD] Theoretically you can try to play with WM_PRINT or
WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then copy
it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much
simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will
cover
it
the capture will be corupt.

[PD] WM_PRINT is a windows message - you can send it to a window to ask
it to draw it's contents on the provided device context (hdc). You can
create hdc (i.e. by calling GetHdc of your Graphics class instance) and
pass it as a parameter to SendMessage, so that window will draw on your
graphics. Look hier for sample code (I have just found it so don't know
if it works but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/

[PD] Can you describe what problems do you have with solutions I have
posted above? The second one looks like it should work (I haven't tested
it but the code looks OK).
 
P

Piotr Dobrowolski

The second method generate an cast exception on IHTMLElementRender
render =
(IHTMLElementRender) element;
Moreover, it is not based on WebBrowser Control within framework 2.0.

[PD] Yes, this solution is based on ActiveX browser control. But you can
also access unmanaged interfaces of document using
webBrowser.Document.DomDocument property. You can cast it to
IHTMLDocument2 just like in this article and move on.
The first method doesn't work. It seems WebBrowser doesn't managed
WM_PRINT...

Piotr Dobrowolski said:
I try the two methods, but it doesn't give me entire satisfaction.

I really would like to reproduce behavior of DrawToBitmap for a
WebBrowser
Control...

How can I do that ?


"Prosperz" <[email protected]> a écrit dans le message de
[email protected]...
More generally, is there an opensource control that made this
functionality ?

I found : websnapshot and dypswebcapture but you must paid to use
them.

Any tools ?


"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans
le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 20:32:46 Prosperz <[email protected]>
napisal:

I never used WM_PRINT and I don't know how to use it. Can you be
more
precise ?

I would like to precise that I want to make a screenshot of an
entire
web
page even if only a part is visible in the WebBrowser...

Maybe I must not use WebBroser to do that.

"Piotr Dobrowolski" <Piotr.Dobrowolski@_usun_gmail.com> a écrit dans
le
message de news: (e-mail address removed)...
Dnia 29-03-2006 o 19:18:40 Prosperz <[email protected]>
napisa³:

Hi,

I would like to make thumbnails of web page by capture content of
a
WebBrowser. By example, capture http://www.google.com.

I used WebBrowser control with Framework 2.0.

I try this :

*************************************************
WebBrowser w = (WebBrowser)sender;

Rectangle rec = w.Bounds;

Bitmap bitm = new Bitmap(rec.Width, rec.Height);

w.BringToFront();

w.DrawToBitmap(bitm, rec);

picScreenshot.Image = bitm;

bitm.Save(@"c:\temp.jpg");

bitm.Dispose();

*************************************************


But it doesn't work (DrawToBimap seems to be not managed by the
WebBrowser
control).

How can I do to make these kind of thumbnails ?

[PD] Theoretically you can try to play with WM_PRINT or
WM_PRINTCLIENT
message (create HDC and send it as a param of a message an then
copy
it
to
the graphics). I have done that with some controls and it works,
unfortunately I don't have any sample code now. The second, much
simpler
but also a little bit less elegant idea is to do it this way:
destinationGraphics.CopyFromScreen(
webBrowser.PointToScreen(new Point(0, 0)),
new Point(0, 0), webBrowser.Size);

Of course your control must be fully visible - if any window will
cover
it
the capture will be corupt.

[PD] WM_PRINT is a windows message - you can send it to a window to
ask
it to draw it's contents on the provided device context (hdc). You
can
create hdc (i.e. by calling GetHdc of your Graphics class instance)
and
pass it as a parameter to SendMessage, so that window will draw on
your
graphics. Look hier for sample code (I have just found it so don't
know
if it works but looks ok):
http://tommycarlier.blogspot.com/2004/12/painting-control-onto-graphics-object.html

I'm not sure if this solution is good for your problem - probably
there
are better ways to do that - look at this article, it looks valuable:
http://www.developerfusion.co.uk/show/4712/

[PD] Can you describe what problems do you have with solutions I have
posted above? The second one looks like it should work (I haven't tested
it but the code looks OK).
 

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