猿问

字节数组到图像asp.net

我有一个表示图片的字节数组。我想在aspx页面中显示存储在该字节数组中的图片。我可以使用图像或图像地图控件来做到吗?如果是这样-如何?如果没有-解决方案是什么?



九州编程
浏览 468回答 3
3回答

弑天下

您可以编写一个通用的处理程序来处理图片:<%@ WebHandler Language="C#" Class="Picture" %>public class Picture : System.Web.IHttpHandler{&nbsp; &nbsp; public void ProcessRequest(HttpContext context)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = GetPictureFromSomewhere();&nbsp; &nbsp; &nbsp; &nbsp; context.Response.ContentType = "image/jpeg";&nbsp; &nbsp; &nbsp; &nbsp; context.Response.OutputStream.Write(buffer, 0, buffer.Length);&nbsp; &nbsp; }&nbsp; &nbsp; public bool IsReusable&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; get { return false; }&nbsp; &nbsp; }}然后在aspx页面中调用它:<asp:Image ID="pic" runat="server" ImageUrl="~/Picture.ashx" />
随时随地看视频慕课网APP
我要回答