如何将图像URL转换为system.drawing.image

编程入门 行业动态 更新时间:2024-10-22 13:45:26
本文介绍了如何将图像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 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 = "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("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("localhost/image.gif") Dim ms As New MemoryStream(bytes) Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)

更多推荐

如何将图像URL转换为system.drawing.image

本文发布于:2023-11-01 12:35:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549350.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   图像   image   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!