【问题标题】:cant show byte[] image in FF and Chrome?无法在 FF 和 Chrome 中显示 byte[] 图像?
【发布时间】:2013-12-23 08:32:13
【问题描述】:

我正在显示数据库中存储为Varbinary(Max)的图像

在 Razor 中,我将其转换为字符串并以 <img> 的形式播种。它适用于 IE,但不适用于 FF 和 Chrome。我已经尽力了,但无法弄清楚为什么会这样。请帮忙。

请在 IE(工作)和(FF 和 Chrome 都不能工作)中查看这个生成的 html:

http://jsfiddle.net/MGY9Y/

注意: 我正在使用以下代码从 Asp.Net MVC Razor 生成此 html:

<img src=@(!Model.Photos.Any() ? "/Content/Images/Cars/CarPlaceHolder.jpg" 
:Encoding.ASCII.GetString(Model.Photos.FirstOrDefault().Document))></img>

【问题讨论】:

    标签: html asp.net-mvc google-chrome asp.net-mvc-4 firefox


    【解决方案1】:

    我也在做同样的事情,但方法不同.. 控制器

       using (var binaryReader = new BinaryReader(Request.Files["files"].InputStream))
                {
                    Image = binaryReader.ReadBytes(Request.Files["files"].ContentLength);
                }
    

    查看

       if (Model.Logo != null)
          {
             string imageBase64 = Convert.ToBase64String(Model.Logo);
             string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);
             <img src="@imageSrc" class="self-image" />
          }
      else 
          {
             <img src=YOUR IMAGE class="self-image" />
          }
    

    它在 IE 和 chrome 中都可以工作

    【讨论】:

    • 谢谢,只是想确认它在 FF 和 Chrome 中是否有效?谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-12-26
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2020-09-12
    • 2015-08-03
    • 1970-01-01
    相关资源
    最近更新 更多