在网上找了一些资料做了一个网站全屏截图的小程序,但为什么像www.163.com这类网站截出来的图是空白的呢?求赐教!~
代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private WebBrowser _webBrowser;
private void button1_Click(object sender, EventArgs e)
{
string url = textBox1.Text;
_webBrowser = new WebBrowser();
_webBrowser.ScrollBarsEnabled = false; //不显示滚动条
_webBrowser.Navigate(url);
_webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Completed); while (_webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents(); //避免假死,若去掉则可能无法触发 DocumentCompleted 事件。
}
MessageBox.Show("OK");
}
public void Completed(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//设置浏览器宽度、高度为文档宽度、高度,以便截取整个网页。
_webBrowser.Width = _webBrowser.Document.Body.ScrollRectangle.Width;
_webBrowser.Height = _webBrowser.Document.Body.ScrollRectangle.Height;
using (Bitmap bmp = new Bitmap(_webBrowser.Width, _webBrowser.Height))
{
_webBrowser.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(textBox2.Text+"\\"+ textBox1.Text + "." + comboBox1.Text);
}
} private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
textBox2.Text = path.SelectedPath;
}
}
}
代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private WebBrowser _webBrowser;
private void button1_Click(object sender, EventArgs e)
{
string url = textBox1.Text;
_webBrowser = new WebBrowser();
_webBrowser.ScrollBarsEnabled = false; //不显示滚动条
_webBrowser.Navigate(url);
_webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Completed); while (_webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents(); //避免假死,若去掉则可能无法触发 DocumentCompleted 事件。
}
MessageBox.Show("OK");
}
public void Completed(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//设置浏览器宽度、高度为文档宽度、高度,以便截取整个网页。
_webBrowser.Width = _webBrowser.Document.Body.ScrollRectangle.Width;
_webBrowser.Height = _webBrowser.Document.Body.ScrollRectangle.Height;
using (Bitmap bmp = new Bitmap(_webBrowser.Width, _webBrowser.Height))
{
_webBrowser.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(textBox2.Text+"\\"+ textBox1.Text + "." + comboBox1.Text);
}
} private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
textBox2.Text = path.SelectedPath;
}
}
}
http://topic.csdn.net/u/20090702/11/845f5ac5-48f2-463a-8271-47c5eeb33cab.html?50190
页面是否加载完成