Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm looking for source code on how to convert an entire HTML page into a BITMAP image. Not a screenshot; I'm able to get that. But my BITMAP needs to save what is not currently displayed as well(scroll).

 

Any help would be greatly appreciated!

Thanks in advance

Ben

Posted

The following code will produce a �form� screen shot

 

Private Sub btnSave_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnSave.Click

' Save the picture.

Dim bm As Bitmap = GetFormImage()

bm.Save("c:\newread\test.tif", System.Drawing.Imaging.ImageFormat.Tiff)

'Beep()

End Sub

 

Private Function GetFormImage() As Bitmap

Dim me_gr As Graphics = Me.CreateGraphics

Dim bm As New Bitmap(Me.ClientSize.Width, _

Me.ClientSize.Height, me_gr)

Dim bm_gr As Graphics = me_gr.FromImage(bm)

Dim bm_hdc As IntPtr = bm_gr.GetHdc

Dim me_hdc As IntPtr = me_gr.GetHdc

BitBlt(bm_hdc, 0, 0, Me.ClientSize.Width, _

Me.ClientSize.Height, _

me_hdc, 0, 0, SRCCOPY)

me_gr.ReleaseHdc(me_hdc)

bm_gr.ReleaseHdc(bm_hdc)

Return bm

End Function

 

You�ll need to declare the BitBlt function and the variable SRCCOPY after your Public Class Form1

 

Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _

hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _

nYDest As Integer, ByVal nWidth As Integer, ByVal _

nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _

As Integer, ByVal nYSrc As Integer, ByVal dwRop As _

System.Int32) As Boolean

 

Private Const SRCCOPY As Integer = &HCC0020

Posted

Now, as far as rendering the HTML page to a bitmap, I�ve come this far (doing my best to interpret Rob Manderson�s C++ article into VB.NET). I don�t get an error when I render my HTML page to the device context; at least that�s what I think I�m doing. I only now need to get my device context rendering into a bitmap, but I�m stuck. Do I need to use the BitBlt function?

 

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

Dim doc As mshtml.HTMLDocument = DirectCast(Me.AxWebBrowser1.Document,

mshtml.HTMLDocument)

Dim bodyElement As mshtml.IHTMLElement

Dim render As mshtml.IHTMLElementRender

Dim render2 As IHTMLElementRender

Dim dd As mshtml.HTMLBody

 

bodyElement = doc.body

render2 = bodyElement

 

Dim BitMap As New Bitmap(600, 400)

Dim g As Graphics = Graphics.FromImage(BitMap)

Dim memDC As IntPtr

 

memDC = g.GetHdc()

 

render2.DrawToDC(memDC)

 

Try

BitMap.FromHbitmap(memDC)

Catch exc As Exception

MsgBox(Err.Description)

MsgBox(exc.ToString)

End Try

 

BitMap.Save("c:\newread\test.tif", System.Drawing.Imaging.ImageFormat.Tiff)

MsgBox("Image created!")

End Sub

 

The following code is after your imports but before your Public Class Form1

 

<ComVisible(True), ComImport(), _

Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"), _

InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _

Interface IHTMLElementRender

Sub DrawToDC(<[in]()> ByVal hDC As IntPtr)

Sub SetDocumentPrinter(<[in](), MarshalAs(UnmanagedType.BStr)> ByVal _

bstrPrinterName As String, <[in]()> ByVal hDC As IntPtr)

End Interface 'IHTMLElementRender

 

It must be needed so DrawToDc accepts a normal pointer rather than a remotable handle

 

Any help would be appreciated!

Thank in advance

Ben

Posted

Thanks much, Tygur

 

I downloaded that program and it works really quite well. I'm set for now.

 

In my spare time I can try to translate the C++ code into VB.NET code. (If it's possible...)

 

Thanks again

  • 1 month later...
Posted

Trouble in Rivercity...

 

Hello once again.

 

I ended up downloading the IECapt.exe program, which does a great job of capturing a url to an image. However, if the url is generic and not a direct reflection of the web page itself, it does me no good.

 

Is there anyone who could help me save the contents of my axWebBrowser to an image??? I would be forever grateful.

 

Thanks again in advance,

Ben

  • 4 weeks later...
Posted

Well I figured out how to capture the Web Browser, scroll down a page, capture again, and continue until I'm at the end. Then I just concatenate all the images together into one. It's "flashy" and a "tad too early 90s", but it works.

 

Anyone have a method of capturing the Web Browser in one quick, swift stroke? VB.NET

 

Thanks

Ben

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...