一个网页,它是显示图片,但在一些浏览器,它却显示如下:
图片不能显示

 

Insus.NET猜,不是浏览器不兼容,就是代码有问题。

图片不能显示

 

在代码中,只是输出数据流,图片格式很多种,如jpg,png,bmp等,没有指定,程序也不清楚要显示什么格式的图片。
因此,Insus.NET把代码改为如下:
图片不能显示

context.Response.Buffer = false;
        FileStream inStr = null;
        byte[] buffer = new byte[1024];
        long byteCount;
        inStr = File.OpenRead(path);
        while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
        {
            if (context.Response.IsClientConnected)
            {
                context.Response.ContentType = "image/png";
                context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                context.Response.Flush();
            }
        }
Source Code

相关文章:

  • 2021-10-28
  • 2021-04-17
  • 2022-03-07
  • 2021-11-28
  • 2022-01-19
  • 2021-11-22
  • 2022-12-23
  • 2021-08-03
猜你喜欢
  • 2021-10-28
  • 2022-02-05
  • 2021-11-28
  • 2021-11-28
  • 2021-12-22
  • 2021-12-10
相关资源
相似解决方案