Public Function DownloadImageFromUrl(ByVal imageUrl As String) As System.Drawing.Image
Dim image As System.Drawing.Image = Nothing
Try
Dim webRequest As System.Net.HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(imageUrl), System.Net.HttpWebRequest)
webRequest.AllowWriteStreamBuffering = True
webRequest.Timeout = 30000
Dim webResponse As System.Net.WebResponse = webRequest.GetResponse()
Dim stream As System.IO.Stream = webResponse.GetResponseStream()
image = System.Drawing.Image.FromStream(stream)
webResponse.Close()
Catch ex As Exception
Return Nothing
End Try
Return image
End Function
Dim image As System.Drawing.Image = Nothing
Try
Dim webRequest As System.Net.HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(imageUrl), System.Net.HttpWebRequest)
webRequest.AllowWriteStreamBuffering = True
webRequest.Timeout = 30000
Dim webResponse As System.Net.WebResponse = webRequest.GetResponse()
Dim stream As System.IO.Stream = webResponse.GetResponseStream()
image = System.Drawing.Image.FromStream(stream)
webResponse.Close()
Catch ex As Exception
Return Nothing
End Try
Return image
End Function
No comments:
Post a Comment