html5 - Raw image data conversion in javascript -


i raw image data server, best options draw on canvas , how do it? please give insight new html , javascript. want know how convert raw data , draw on canvas in html , javascript, if know width , height of raw image.basically dont know format of raw image need conversion.

you can use context.createimagedata create imagedata object can fill rgba data server:

example code demo: http://jsfiddle.net/m1erickson/xtatb/

// test data fill 30x20 canvas red pixels  // test width/height 30x20 var canvaswidth=30; var canvasheight=20;  // resize canvas  canvas.width=canvaswidth; canvas.height=canvasheight;  // create test data (you can use server data in production) var d=[]; for(var i=0;i<canvaswidth*canvasheight;i++){     // red & alpha=255 green & blue = 0     d.push(255,0,0,255); }  // create new imagedata object specified dimensions var imgdata=ctx.createimagedata(canvaswidth,canvasheight);  // data property of imagedata object // array filled test data var data=imgdata.data;  // copy test data (d) imagedata.data (data) for(var i=0;i<data.length;i++){     data[i]=d[i]; }  // push modified imagedata object canvas ctx.putimagedata(imgdata,0,0); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -