在ASP.NET C#流字节[]到图像 [英] Streaming byte[] to Image in ASP.NET C#

查看:207
本文介绍了在ASP.NET C#流字节[]到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像存储在存储与检索我一次全部我的用户数据我的SQL Server数据库。

现在我有一个字节[]直接在页面上我想表明它。我怎么把我的WebControls.Image?我不希望有打电话给一个HttpHandler并再次调用数据库。

这显然只是其输出到整个页面。

  Context.Response.BinaryWrite(user.Picture.ToArray());


解决方案

如果这是你将它输出为base64 EN codeD数据成图像标签的小图像。
<一href=\"http://stackoverflow.com/questions/1222246/displaying-an-image-in-a-webbrowser-control-without-accessing-external-files/1222280#1222280\">See这里有类似的情况。

但在任何情况下99.9%,您将创建一个返回图像的HttpHandler的。它是这样做,我认为最简单和最快的方式。

I have an Image stored in my SQL Server database stored with my User data which I retrieve all at once.

Now I have the byte[] directly on the page I want to show it on. How do I put it in my WebControls.Image? I don't want to have to call an HttpHandler and call the database again.

This obviously just outputs it to the whole page.

            Context.Response.BinaryWrite(user.Picture.ToArray());

解决方案

If it is a small image you would output it as base64 encoded data into an image-tag. See here for a similar situation.

But in 99.9% of all situations you would create a HttpHandler that returns the image. It is the easiest and fastest way to do it I think.

这篇关于在ASP.NET C#流字节[]到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆