CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  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
    Mar 2005
    Posts
    20

    Re: HTML to BMP in VB.NET

    Thanks a million for taking the time to respond to this thread, it means a lot to me.

    I tried modifying my code with your suggestions and it saved a "black" image. The webpage displayed in my axWebBrowser (www.yahoo.com) did not appear as my saved bitmap.

    DrawToDC as far as I can tell draws the contents of my axWebBrowser to a specified device context, which is memDC in this case

    render2.DrawToDC(memDC)

    I think my next step is to perform a BitBlt or maybe a CreateCompatibleBitmap??? I'm not entirely sure? In fact, I'm not actually sure about any of my code except for my DirectCast captures the contents of my axWebBrowser into a document. But from there on end I'm sure of nothing...

    Any thoughts?
    Ben

  8. #8
    Join Date
    Mar 2005
    Posts
    20

    Re: HTML to BMP in VB.NET

    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

  9. #9
    Join Date
    Jun 2005
    Posts
    1

    Re: HTML to BMP in VB.NET

    woklet,

    I am looking at trying to save a html to an image as well. So I can surf the web on my PVR. Do you mind sharing the code that you have for doing this?

    Jdubin

  10. #10
    Join Date
    Jun 2007
    Posts
    1

    Re: HTML to BMP in VB.NET

    Quote Originally Posted by woklet
    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
    This is a good article describing how to do this:

    http://www.codeproject.com/cs/media/IECapture.asp

    However, no one seems to have fixed the "black screen" problem on some sites, for example msn.com. I'm trying to figure out why it's happening, it might be a problem with the doctype, or flash ads or something. Any help is greatly appreciated!

    Thanks,
    Sire

  11. #11
    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.

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    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
  •  





Click Here to Expand Forum to Full Width

Featured