Home All Groups Group Topic Archive Search About

Save image of webbrowser control?

Author
19 Mar 2006 10:22 PM
dgk
How can I capture an image of a websession? Something like this where
wb1 is a webbrowser?

    Dim g As Graphics = wb1.CreateGraphics()
    Dim img As Bitmap = g.CopyFromScreen(New Point(0, 0), New Point(0,
0), )
    g.Dispose()

I have no idea what to put in for the next argument in the CopyFrom
Screen (the size) nor whether this is the way to go about it. I guess
img = wb1.GetMeTheImage would be too easy.

Author
20 Mar 2006 4:17 AM
Ken Tucker [MVP]
Hi,

        Take a look at the drawtobitmap method of the webbrowser control

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap.aspx

Ken
--------------------
Show quoteHide quote
"dgk" <NoWh***@MailsAnonymous.com> wrote in message
news:69mr12t92c3fdcs5rj9jlr641tnt0r3o0f@4ax.com...
> How can I capture an image of a websession? Something like this where
> wb1 is a webbrowser?
>
>    Dim g As Graphics = wb1.CreateGraphics()
>    Dim img As Bitmap = g.CopyFromScreen(New Point(0, 0), New Point(0,
> 0), )
>    g.Dispose()
>
> I have no idea what to put in for the next argument in the CopyFrom
> Screen (the size) nor whether this is the way to go about it. I guess
> img = wb1.GetMeTheImage would be too easy.
Author
20 Mar 2006 5:59 PM
dgk
On Sun, 19 Mar 2006 23:17:24 -0500, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

>Hi,
>
>        Take a look at the drawtobitmap method of the webbrowser control
>
>http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap.aspx
>
>Ken
>--------------------

Closer. But both bitmap and rectangle apparently need to be
instantiated before the call. When I do that, I get a TargetBounds
exception.

Public Class Form1
  Private MyImage As Bitmap = New Bitmap(150, 150)
  Private MyRectangle As New Rectangle
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
    wb1.Navigate("www.google.com")
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

    wb1.DrawToBitmap(MyImage, MyRectangle)
  End Sub
End Class

Any idea how the rectangle should be created?