バイト配列は、各バイトの整数表現に変換されます。Fiddler で表示すると、次のようになります。
{"imageBackground":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,...]}
この整数画像配列をjson Web サービスから asp.net c# のクラスとして取得する方法
バイト配列は、各バイトの整数表現に変換されます。Fiddler で表示すると、次のようになります。
{"imageBackground":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,...]}
この整数画像配列をjson Web サービスから 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 Web フォームに表示する場合は、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" />