0

I would like to know how to extract the raw data from a html5 canvas as raw bitmap pixel data and store it in a variable.

So far I have setup my html5 canvas with an image in it: https://jsfiddle.net/t21mjh5L/1/

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("myimg");
ctx.drawImage(img,0,0);
var bitmapData;
//retrieve image data as raw bitmap
1

1 Answer 1

2

you can try to get bitmap data like this :

var myImageData = ctx.getImageData(left, top, width, height).data;

More information about getting image data can be found here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Your answer helped me find this article which helped me get where I wanted. hacks.mozilla.org/2011/12/…
Also if anyone is interested this is how you can get raw jpeg data: var jpegRawData = canvas.toDataURL("image/jpeg", 1.0).replace("data:image/jpeg;base64,","");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.