HttpHandler 从字节数组中渲染 png
好吧,这应该很简单,但我就是无法让它发挥作用。我有一个字节数组,从 png 文件中读取。我正在尝试编写一个(非常)简单的 HttpHandler 来呈现图像:
context.Response.AddHeader("Content-Type", "image/png")
context.Response.BinaryWrite(bytes)
context.Response.End()
当我在浏览器中打开页面时,我只是得到乱码,
�PNG IHDR���X��sRGB���gAMA���a PHYs���o�d`...
这显然是我做错的标题信息。有什么建议吗?
Okay, this should be simple, but I just can't get it to work. I have an array of bytes, read from a png file. I'm trying to write a (very) simple HttpHandler to render the image:
context.Response.AddHeader("Content-Type", "image/png")
context.Response.BinaryWrite(bytes)
context.Response.End()
When I open the page in a browser, I just get gibberish,
�PNG IHDR���X��sRGB���gAMA�� �a pHYs���o�d` ...
It's obviously something with the header information I'm doing wrong. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
ContentType
属性而不是AddHeader
:另外两个诊断:
Try using the
ContentType
property instead ofAddHeader
:Two more diagnostics: