【问题标题】:Get Image from code behind从后面的代码中获取图像
【发布时间】:2011-10-28 10:58:56
【问题描述】:

如何从后面的代码中获取存储在应用程序文件夹中的图像?

我需要在 byte[] 中转换图像。所以我这样做:

        MemoryStream stream = new MemoryStream();            
        System.Drawing.Image.FromFile(ResolveUrl("~/Icons/CMJN.png")).Save(stream,System.Drawing.Imaging.ImageFormat.Png);
        var foo = stream.ToArray();

但他似乎从未找到带有解析 URL 的图像。 我在一个页面的页面加载中..

【问题讨论】:

    标签: c# asp.net url code-behind


    【解决方案1】:

    使用 Server.MapPath 获取物理文件路径。

    Server.MapPath("~/Icons/CMJN.png")
    

    【讨论】:

      【解决方案2】:

      尝试添加Server.MapPath

      System.Drawing.Image.FromFile(Server.MapPath("~/Icons/CMJN.png")).Save(stream,System.Drawing.Imaging.ImageFormat.Png);
      

      【讨论】:

        猜你喜欢
        • 2016-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-25
        • 2013-10-15
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        相关资源
        最近更新 更多