Render Webpage as Bitmap in GDI+

naeem_s

Newcomer
Joined
Mar 13, 2004
I want to be able to wrap this functionality into a web service.

You could then use it as part of a web search where alongside each search result you could show a thumbnail image of the web page.
 

Arch4ngel

Senior Contributor
Joined
Mar 22, 2004
Location
Montreal, QC
Screenshot maybe ?

naeem_s said:
I want to be able to wrap this functionality into a web service.

You could then use it as part of a web search where alongside each search result you could show a thumbnail image of the web page.
So... you could take a screen shot of your browser in maximize mode dynamicly and transfer it to a Bitmap object and resize it to the right size and save it as a file.

(For the screen shot... you can see it how it's done here.)

Good day ! :D
 

mjb3030

Regular
Joined
Aug 14, 2003
I don't know what steps you would take to do all of this in .NET, but I know that PDF's can be converted to BMP. So, if you printed the web page to a PDF file and then converted it to BMP..... Or, maybe there is a way (perhaps someone has already created a component for this) to print directly to a BMP file. That way you could get the whole page instead of just the portion on the screen.
 

BlackFatPig

Newcomer
Joined
Aug 9, 2008
Dear naeem_s !

I hope my code can help you :eek: :

Private Sub Capture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Capture.Click
Dim w As New WebBrowser()
w.Size = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
w.Navigate("http://www.google.com.vn")
AddHandler w.DocumentCompleted, AddressOf CompletedDoc
End Sub

Private Sub CompletedDoc(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
Dim w As WebBrowser = CType(sender, WebBrowser)
Dim b As New Bitmap(w.Document.Body.ScrollRectangle.Width, w.Document.Body.ScrollRectangle.Height)
w.DrawToBitmap(b, New Rectangle(0, 0, b.Width, b.Height))
b.Save("Your Image File Path Here", Drawing.Imaging.ImageFormat.Jpeg)
b.Dispose()
w.Dispose()
End Sub

Note: the DrawToBitmap method isn't show on context menu, but you still use it :D .

Everything will be OK.
 

Farhomar

Newcomer
Joined
Jan 29, 2008
I use WebsitesScreenshot .NET library in all my projects which require html to image conversion or web page screenshot.
http://www.websitesscreenshot.com/
WebsitesScreenshot.WebsitesScreenshot _Obj;
_Obj = new WebsitesScreenshot.WebsitesScreenshot();
WebsitesScreenshot.WebsitesScreenshot.Result _Result;
_Result = _Obj.CaptureWebpage("http://www.msn.com");
if (_Result == WebsitesScreenshot.
WebsitesScreenshot.Result.Captured)
{
_Obj.ImageWidth = 200;
_Obj.ImageHeight = 300;
_Obj.ImageFormat = WebsitesScreenshot.
WebsitesScreenshot.ImageFormats.PNG;
_Obj.SaveImage("c:\\msn.png");
}
_Obj.Dispose();
 
Top Bottom