How to convert a byte array into an image?

后端 未结 8 2112
一向
一向 2020-12-01 05:51

Using Javascript, I\'m making an AJAX call to a WCF service, and it is returning a byte array. How can I convert that to an image and display it on the web page?

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 06:19

    Instead of calling the service with AJAX, use Javascript to build an image element and point it to the service directly...

    var img = document.createElement("IMG");
    img.src = "http://url/to/service";
    img.alt = "ALT TEXT";
    document.body.appendChild(img);
    

    Just make sure the service sets the content type properly.

提交回复
热议问题