4
我想將* .aspx(HTML)頁面(用戶界面)轉換爲圖像,如JPEG。 我使用下面的代碼爲如何將網頁轉換爲圖像?
Protected Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click
saveURLToImage("http://google.co.in")
End Sub
Private Sub saveURLToImage(ByVal url As String)
If Not String.IsNullOrEmpty(url) Then
Dim content As String = ""
Dim webRequest__1 As System.Net.WebRequest = WebRequest.Create(url)
Dim webResponse As System.Net.WebResponse = webRequest__1.GetResponse()
Dim sr As System.IO.StreamReader = New StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"))
content = sr.ReadToEnd()
'save to file
Dim b As Byte() = Convert.FromBase64String(content)
Dim ms As New System.IO.MemoryStream(b, 0, b.Length)
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
img.Save("c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
img.Dispose()
ms.Close()
End If
End Sub
但是我收到錯誤爲「在鹼-64串無效字符」在線 昏暗b以字節()= Convert.FromBase64String(內容)
是否要保存HTML代碼爲JPG或者呈現的html(就像你在瀏覽器中打開url時看到的那樣)? – 2010-06-10 08:35:27
我只是問,因爲你的代碼建議第一個。即使你解決了你的錯誤,它也不會工作。你不能只是拿一個字符串,並保存爲一個像這樣的jpeg。你必須以某種形式使用DrawString() – 2010-06-10 08:42:45