且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不能呈现图像HttpContext.Response.OutputStream

更新时间:2023-11-10 20:22:52

作家确实如此。需要寻求流正确地书写。

The writer indeed needs to seek to write in the stream properly.

但你最后的源代码,请确保你使用任何MemoryStream.ToArray()来获取正确的数据或如果你不想复制数据,使用MemoryStream.GetBuffer()与MemoryStream.Length和返回数组不是长度。

But in your last source code, make sure that you do use either MemoryStream.ToArray() to get the proper data or, if you do not want to copy the data, use MemoryStream.GetBuffer() with MemoryStream.Length and not the length of the returned array.

的GetBuffer将返回内部缓冲液使用将MemoryStream,其长度一般比已写入流数据的长度长。

GetBuffer will return the internal buffer used by the MemoryStream, and its length generally greater than the length of the data that has been written to the stream.

这将避免你在最后发送垃圾流,而不是搞砸了一些严格的图像解码器,它不会容忍尾随的垃圾。 (和传输的数据更少......)

This will avoid you to send garbage at the end of the stream, and not mess up some strict image decoder that would not tolerate trailing garbage. (And transfer less data...)