CSharp - 如何将图像url转换为 system.drawing.image

  显示原文与译文双语对照的内容
0 0

我正在使用 VB.Net 我有一个图像的url,比如说 http://localhost/image.gif

我需要从那个文件中创建一个 System.Drawing.Image 对象。

注意保存这个文件,然后打开它不是我的选项之一,我使用 ItextSharp

这是我的代码:


Dim rect As iTextSharp.text.Rectangle
 rect = iTextSharp.text.PageSize.LETTER
 Dim x As PDFDocument = New PDFDocument("chart", rect, 1, 1, 1, 1)

 x.UserName = objCurrentUser.FullName
 x.WritePageHeader(1)
 For i = 0 To chartObj.Count - 1
 Dim chartLink as string ="http://localhost/image.gif"
 x.writechart( ** it only accept system.darwing.image ** ) 

 Next

 x.WritePageFooter()
 x.Finish(False)

时间: 原作者:

0 0

可以使用 WebClient 类下载图像,然后使用MemoryStream读取图像:

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)

原作者:
0 0

你可以试试这个


Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("[URL here]")
Dim response As System.Net.WebResponse = req.GetResponse()
Dim stream As Stream = response.GetResponseStream()

Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(stream)
stream.Close()

原作者:
0 0

Dim c As New System.Net.WebClient
Dim FileName As String ="c:StackOverflow.png"
c.DownloadFile(New System.Uri("http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=5"), FileName)
Dim img As System.Drawing.Image
img = System.Drawing.Image.FromFile(FileName)

0 0

iTextSharp能够接受:uri


Image.GetInstance(uri)

...