Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can JavaScript load raw bytes to use in HTML5 Canvas?

Say I had a URL like

http://my.website.com/myfile.raw

and this file it points to was just raw bytes, representing an intensity image. Is it possible to grab this data and read the bytes in JavaScript? And then using it with HTML5 canvas (e.g. putImageData) to draw an image?

Or is there some other way to do this in the browser without Java or Flash?

like image 449
whiskeyspider Avatar asked Apr 09 '10 02:04

whiskeyspider


People also ask

Is HTML5 canvas still used?

The HTML5 canvas has the potential to become a staple of the web, enjoying ubiquitous browser and platform support in addition to widespread webpage support, as nearly 90% of websites have ported to HTML5.

Does HTML5 support canvas element?

The canvas element is part of HTML5 and allows for dynamic, scriptable rendering of 2D shapes and bitmap images.

What is use of canvas in HTML5?

The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.

How fast is HTML canvas?

The Canvas tab loaded in one second and takes up 30MB. It also takes up 13% of CPU time all of the time, regardless of whether or not one is looking at it.


1 Answers

maybe

function draw() {
    var ctx = document.getElementById('canvas').getContext('2d');
    var img = new Image();
    img.onload = function(){
      ctx.drawImage(img,0,0);
      imageData = ctx.getImageData(0, 0, image.width, image.height)
      //now you can do something with imageData...
    }
    img.src = 'http://my.website.com/myfile.raw';
  }
like image 85
Drew LeSueur Avatar answered Nov 05 '22 06:11

Drew LeSueur