【问题标题】:Reading streams from image on a web page in asp.net从asp.net网页上的图像读取流
【发布时间】:2014-08-05 07:48:48
【问题描述】:

我在我的 asp.net 网站的图像控件中绑定了一个图像。

我正在使用 C# 来开发它。下面是绑定图片的代码。

 byte[] imageBytes = System.IO.File.ReadAllBytes("filepath");
 string base64String = Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
 this.testImage.Src = "data:image/jpeg;base64," + base64String;

现在我想在另一个事件中从该图像控件 (testImage) 中获取流。 我不想将图像保存在任何服务器路径中。

我该怎么做?

提前致谢。

【问题讨论】:

    标签: c# asp.net image stream iostream


    【解决方案1】:

    试试这个:

    WebClient webClient = new WebClient();
    Image img = Image.FromStream(webClient.OpenRead(path));
    webClient.Dispose();
    

    仅当图像不是硬盘上的文件时才适用。

    如果图像在硬盘上,应该这样做:

    Image img = Image.FromFile(path);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 2011-02-12
      • 1970-01-01
      • 2021-10-01
      • 2012-11-27
      • 1970-01-01
      相关资源
      最近更新 更多