How can I convert image url to system.drawing.image

前端 未结 6 951
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 06:53

I\'m using VB.Net I have an url of an image, let\'s say http://localhost/image.gif

I need to create a System.Drawing.Image object from that

6条回答
  •  臣服心动
    2020-12-13 07:17

    You could use WebClient class to download image and then MemoryStream to read it:

    C#

    WebClient wc = new WebClient();
    byte[] bytes = wc.DownloadData("http://localhost/image.gif");
    MemoryStream ms = new MemoryStream(bytes);
    System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    

    VB

    Dim wc As New WebClient()
    Dim bytes As Byte() = wc.DownloadData("http://localhost/image.gif")
    Dim ms As New MemoryStream(bytes)
    Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
    

提交回复
热议问题