I am extracting an byte array from pictureStream from a .net webservice. The response of the JSON byte array is as follows:
[137, 80, 78, 372, 617 more...]
I am trying to convert this byte array and draw it into an HTML canvas like this
var context = document.getElementById('boxcover').getContext('2d'); context.putImageData(movies.PictureStream, 0, 0);
But that does not work. I do not have access to change the web service, so I want to convert this byte array to an image using Javascript only. In addition, I can not use scripts on the server side, only on the client side.
thanks for the help
Here's an example of how an array of bytes comes in: http://www.copypastecode.com/33072/
, . RGB RGBA, getImageData/putImageData, , , Kieranmaine.
- jpeg , , , . 64, dataURI, , dataURI drawImage, .
URI , mime. , .
'data:image/png;base64,' + btoa(String.fromCharCode.apply(this, byteArray));
src img , , drawImage() .
getImageData (x, y, width, height), .
, , 3 , getImageData, , . url:
http://jsfiddle.net/WXfPF/1/
. getPixel HTML Canvas?.
Source: https://habr.com/ru/post/1756060/More articles:Итерация через YQL JSON приводит к геопространствам через javascript - jsonHTTPHandler: IRequiresSessionState Stops Page Execution - asp.netВопрос о программировании ядра Unix/Linux - linuxHow to convert ASCII extended names to HTML objects in Python? - pythonH2 Database: Support for Clustered Indexes - clustered-indexRails on Windows connects to Microsoft SQL Server - "no such file to download - odbc" - sql-serverCreate rails locale yaml file automatically? - ruby | fooobar.comIs it possible for an Android application to dial a remote modem and send information back and forth? - androidCompiling a kernel into a binary file on mac - binaryaccess to the last 2 bytes of an integer - c ++All Articles