如何将图像URL转换为system.drawing.image [英] How can I convert image url to system.drawing.image
本文介绍了如何将图像URL转换为system.drawing.image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 VB.Net
我有一个图片的网址,假设 http://localhost/image.gif
I'm using VB.Net
I have an url of an image, let's say http://localhost/image.gif
我需要从该文件创建一个System.Drawing.Image对象。
I need to create a System.Drawing.Image object from that file.
注意将此保存到文件然后打开它不是我的选项之一
我也在使用 ItextSharp
Notice save this to a file and then open it is not one of my options
also i'm using 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)
推荐答案
您可以使用WebClient类下载图像,然后使用MemoryStream来读取它:
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)
这篇关于如何将图像URL转换为system.drawing.image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文