将imageUrl转换为byte []以进行缓存

时间:2010-12-17 16:15:30

标签: c# asp.net

我有一张从ip相机捕获的图像,并将其在网页上发布到图像标记。现在我想转换为访问图片,以便我可以将其保存到我们的缓存blob。这是我的代码:

asp标签:

<asp:Image ID="imgPhoto" runat="server" ImageAlign="Middle" />

图像分配背后的代码:

imgPhoto.ImageUrl = "http://10.10.40.35/axis-cgi/jpg/image.cgi?resolution=640x480";

我尝试将图像转换为byte []:

System.Drawing.Image _newImage = System.Drawing.Image.FromFile(imgPhoto.ImageUrl);
MemoryStream ms = new MemoryStream();
_newImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] _fileBytes = new byte[ms.Length];

1 个答案:

答案 0 :(得分:6)

byte[] image = (new WebClient()).DownloadData(imgPhoto.ImageUrl);