<分区>
Possible Duplicate:
How to deserialize json image(byet array)into image in asp.net?
字节数组被转换为每个字节的整数表示。在 Fiddler 中查看时,它看起来像
{"imageBackground":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,...]}
如何从 json 网络服务 中检索此整数图像数组 作为 asp.net c# 中的类
<分区>
Possible Duplicate:
How to deserialize json image(byet array)into image in asp.net?
字节数组被转换为每个字节的整数表示。在 Fiddler 中查看时,它看起来像
{"imageBackground":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,...]}
如何从 json 网络服务 中检索此整数图像数组 作为 asp.net c# 中的类
最佳答案
假设你有一个字节数组:
byte[] imageBackground = new byte[] { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,... };
你可以创建一个 Image
:
using (var stream = new MemoryStream(imageBackground))
using (var image = Image.FromStream(stream))
{
// do something with the image
}
或者如果您想在 ASP.NET 网络表单上显示它,请在 Image
内控件,您可以编写一个通用处理程序,将此图像流式传输到响应:
public class ImageHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
var response = context.Response;
byte[] imageBackground = new byte[] { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,... };
response.OutputStream.Write(imageBackground, 0, imageBackground.Length);
response.ContentType = "image/jpeg";
}
}
然后将 Image 控件指向这个通用处理程序:
<asp:Image runat="server" ID="myimage" ImageUrl="~/imagehandler.ashx" />
关于c# - 二进制数组在asp.net中成像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117731/