How to save a web page as an image

I have a line with the source of the web page; how can i save it in byte [] as image?

+4
c # image webpage
Mar 17 '11 at 10:28
source share
3 answers

Here: http://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx

An example of using the WebBrowser.DrawToBitmap method.

Once you have created the bitmap, you can compress it using whatever encoding you want.
This is an example from MSDN for how to compress PNG (lossless and small):
A practical guide. Encoding and decoding PNG images

Good luck :)

EDIT:
To get an array of bytes, you can use a memory stream as an output stream.

Here is a working example of how this works:

public static void Main(string[] args) { byte[] test = new byte[] { 2, 5, 6, 1, 9 }; MemoryStream ms = new MemoryStream(); ms.Write(test, 0, 5); byte[] image = new byte[ms.Length]; Buffer.BlockCopy(ms.GetBuffer(), 0, image, 0, (int)ms.Length); for (int i = 0; i < ms.Length; i++) Console.WriteLine(image[i]); Console.ReadKey(); } 

And here is an example of how it will work in your case:

 public static void Main(string[] args) { MemoryStream ms = new MemoryStream(); // You have a PNGBitmapEncoder, and you call this: encoder.Save(ms); byte[] image = new byte[ms.Length]; Buffer.BlockCopy(ms.GetBuffer(), 0, image, 0, (int)ms.Length); for (int i = 0; i < ms.Length; i++) Console.WriteLine(image[i]); Console.ReadKey(); } 
+4
Mar 17 '11 at 10:35
source share

You can take a look at the following article and this one , which illustrate one way to take a screenshot of a web page and save it as an image. The WPFChromium component also allows you to achieve this, regardless of Internet Explorer.

+2
Mar 17 '11 at 10:39
source share

Look to display webpage for image

0
Mar 17 '11 at 10:50
source share



All Articles