Geting an Image of the Page in a Web Browser Control

I would like to know how, if its possible, to get an image of the page loaded into a web browser control


Answer this question

Geting an Image of the Page in a Web Browser Control

  • Zeldacat

    It runs absolutely fine here. I'm unable to replicate any problem.



  • Rajnesh

    I knew it would. It's good code. You need to do something about a path spec but other than that, it's nice code.



  • Kevin Rodgers

    Imports System.drawing

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles Me.Load

    Wb.Navigate("www.microsoft.com")

    Wb.Location = New Point(0, 0)

    End Sub

    Private Sub cbGo_Click(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles cbGo.Click

    Const ScrollbarWidth = 18

    Dim wbRect As Rectangle = Wb.ClientRectangle

    Dim wbBm As New Bitmap(Wb.ClientRectangle.Width - ScrollbarWidth, _

    Wb.ClientRectangle.Height - ScrollbarWidth)

    Dim gwb As Graphics = Graphics.FromImage(wbBm)

    gwb.CopyFromScreen(Wb.PointToScreen(New Point(0, 0)), New Point(0,
    0), New Size(Wb.Width - ScrollbarWidth, _

    Wb.Height - ScrollbarWidth))

    gwb.Dispose()

    wbBm.Save("c:\temp\deleteme.png")

    wbBm.Dispose()

    End Sub

    End Class



  • samaya78

    i tried that at and it gave me the following error whe it executed wbBm.Save("c:\temp\deleteme.png") :

    System.Runtime.InteropServices.ExternalException was unhandled
    ErrorCode=-2147467259
    Message="A generic error occurred in GDI+."
    Source="System.Drawing"
    StackTrace:
    at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at System.Drawing.Image.Save(String filename, ImageFormat format)
    at System.Drawing.Image.Save(String filename)
    at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in F:\Documents and Settings\owner\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb:line 20
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()



  • KimberlyL

    Hi,

    Nice to see you again! This time I just found an article in Microsoft Knowledge Base that titled How to display images from a folder in a form, a report, or a data access page.

    http://search.support.microsoft.com/kb/285820/

    I hope this article will help you with your problem after taking a reference :-)



  • mobigital

    luckly i do

  • Loki70

    tried it again and i worked.

  • ravi_9793

    i looked at the article and it wasnt able to help me, thou i do have other uses for it.

    i want to now how to get an image of the page be displyed in a System.Windows.Forms.WebBrowser control.



  • Wenqing Gu

    I tested it, and got the same error because I don't have the c:\temp folder. It worked once I created the folder, so the error is definitely caused by not having the specified folder (as ReneeC suggested earlier), Mr Gates II





  • deadman_dexter

    erm.... do you have a directory called Temp in the root of your C:/ drive



  • Geting an Image of the Page in a Web Browser Control