Save the web page as an image. Remember that this feature was first found in the "Window of the world" browser, As long ago. I never knew how it works.
It's okay to go to work today. I suddenly thought of this problem, so I typed "webbrowser1." in Vs and then I went to see one by one what are the best methods. After a while, I found a more attractive word"Drawtobitmap", Just try it.
Discovery is a method of drawing controls into images. Suddenly realized that this can be used to save webpages as images. So I studied it and came to the conclusion that it is so easy to save it as an image.
Step 1:
First, put a Textbox, button, and webbrowser control on the form.
This . Button1 = New System. Windows. Forms. Button ();
This . Textbox1 = New System. Windows. Forms. Textbox ();
This . Webbrowser1 = New System. Windows. Forms. webbrowser ();
Step 2:
Add button event
VoidButton1click (ObjectSender, eventargs E)
{
Webbrowser1.navigate (textbox1.text );
}
Step 3:
After the webbrowser control loads the webpage, execute this method to start plotting our graph.
Void Webbrowser1documentcompleted ( Object Sender, webbrowserdocumentcompletedeventargs E)
{
Size mysize = Webbrowser1.document. Window. size;
Bitmap mypic = New Bitmap (mysize. Width, mysize. Height );
Rectangle myrec = New Rectangle ( 0 , 0 , Mysize. Width, mysize. Height );
Webbrowser1.size = Mysize;
Webbrowser1.drawtobitmap (mypic, myrec );
Mypic. Save ( " C: \ aaaaaa.jpg " );
MessageBox. Show ( " OK " );
}
Here is an explanation:
1: First LineCode: Obtain the size of the opened webpage.
2: create an image with the size of the webpage content.
3: Create a rectangle;
4: Set the webbrowser size to display the entire page.
5: Use the drawtobitmap function to draw a webbrowser control as an image.
6. Save the image.
7: the prompt is OK.
--------------------
It is so simple that the function of saving a webpage as an image is OK. Of course, we recommend that you hide the webbrowser control to make it more beautiful.