-
March 7th, 2005, 12:57 PM
#1
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
-
March 10th, 2005, 01:50 PM
#2
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."
-
May 2nd, 2005, 10:23 AM
#3
Re: HTML to BMP in VB.NET
Trouble in Rivercity...still need solution!
-
May 2nd, 2005, 11:33 AM
#4
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.
-
May 2nd, 2005, 02:22 PM
#5
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.
-
May 2nd, 2005, 03:25 PM
#6
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.
-
May 3rd, 2005, 11:36 AM
#7
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
-
May 27th, 2005, 01:31 PM
#8
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
-
June 4th, 2005, 01:38 PM
#9
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
-
June 19th, 2007, 04:51 AM
#10
Re: HTML to BMP in VB.NET
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
-
April 14th, 2013, 10:29 PM
#11
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.
-
April 16th, 2013, 10:49 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|