我想將一個Html頁面轉換成圖像文件。爲此,我使用的代碼如何將html頁面轉換爲圖像文件?
我的代碼:
protected void Button1_Click(object sender, EventArgs e)
{
saveURLToImage("http://cg.nic.in/mahasamund/home.htm");
}
private void saveURLToImage(string url)
{
if (!string.IsNullOrEmpty(url))
{
string content = "";
System.Net.WebRequest webRequest = WebRequest.Create(url);
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
content = sr.ReadToEnd();
//save to file
System.Windows.Forms.MessageBox.Show(content);
byte[] b = Convert.FromBase64String(content);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
img.Save(@"d:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
ms.Close();
}
}
,當我運行這段代碼,然後點擊按鈕,然後即
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
有什麼問題發生錯誤? 我該怎麼做?
我已經有這方面的需求。在那段時間,我使用了'PhantomJS',一個可以像瀏覽器一樣打開頁面的'* .exe',你可以拍攝這個畫面。 –