HTML to BMP in VB.NET
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: HTML to BMP in VB.NET

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    20

    HTML to BMP in VB.NET

    I need to save an HTML file as a BMP. I've been able to to a "screen capture" and get a BMP that way, but what is not visible on the screen at the time is not saved. Is there a way to capture the entire HTML page in VB.NET and save it as an image?

    Thanks in advance

  2. #2
    Join Date
    Mar 2005
    Posts
    20

    Re: HTML to BMP in VB.NET

    I'm actually replying to my own post in hopes of generating a possible solution. Here is the code I have thus far...

    Dim doc As mshtml.HTMLDocument = DirectCast(Me.AxWebBrowser1.Document, mshtml.HTMLDocument)
    Dim bodyElement As mshtml.IHTMLElement
    Dim render2 As IHTMLElementRender

    bodyElement = doc.body
    render2 = bodyElement

    Dim BitMap AsNew Bitmap(600, 400)
    Dim g As Graphics = Graphics.FromImage(BitMap)
    Dim memDC As IntPtr
    Dim CCBHandle As IntPtr
    Dim memDC2 As mshtml._RemotableHandle
    Dim tt AsInteger

    memDC = g.GetHdc()
    Try
    render2.DrawToDC(memDC)
    Catch ex As Exception
    MsgBox(ex.ToString)
    EndTry

    Try
    BitMap.FromHbitmap(memDC)
    Catch exc As Exception
    MsgBox(Err.Description)
    MsgBox(exc.ToString)
    EndTry

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


    I don't get an error on my DrawToDC() function, so I feel like I've rendered my HTML page to the Device Context in memory, but by golly I'm not entirely sure.

    Does anyone have further insight in this matter; how to insert what I've rendered into a bitmap? Any thoughts would be helpful.

    Thanks much

    "Go back to the shadow. You shall not pass."

  3. #3
    Join Date
    Mar 2005
    Posts
    20

    Re: HTML to BMP in VB.NET

    Trouble in Rivercity...still need solution!

  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: HTML to BMP in VB.NET

    You can use BitBlt to copy from on hDC to another:

    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
    Private Const SRCCOPY = &HCC0020

    Pass SRCCOPY as teh dwRop Parameter.

  5. #5
    Join Date
    Mar 2005
    Posts
    20

    Re: HTML to BMP in VB.NET

    How??? You'll have to spell it out for me as if I was a first grader, cuz right now my brain is about fried trying to figure this doggone thing out.

  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: HTML to BMP in VB.NET

    Actually, after having reviewed your code again, you're already putting it into the bitmaps hDC, so all you should need is:

    Dim doc As mshtml.HTMLDocument = DirectCast(Me.AxWebBrowser1.Document, mshtml.HTMLDocument)
    Dim bodyElement As mshtml.IHTMLElement
    Dim render2 As IHTMLElementRender

    bodyElement = doc.body
    render2 = bodyElement

    Dim BitMap AsNew Bitmap(600, 400)
    Dim g As Graphics = Graphics.FromImage(BitMap)

    memDC = g.GetHdc()
    Try
    render2.DrawToDC(memDC)
    Catch ex As Exception
    MsgBox(ex.ToString)
    EndTry

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


    I don't us those browser controls, so I'm assuming DrawToDC is doing what we think it is.

  7. #7
    Join Date
    Apr 2013
    Posts
    1

    Re: HTML to BMP in VB.NET

    i like the idea of saving html to an image , that's because i just in love with a new image converter.

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: HTML to BMP in VB.NET

    This thread is 6 Years old! really....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center