Getting values from HTML5 Canvas to JavaScript


When we draw anything on Canvas, it keeps no memory of anything that was drawn. While drawing we need to keep track of all the necessary information yourself as we draw. Therefore, it is not feasible to get value from HTML5 canvas to JavaScript as it keeps no memory. It just draws like this −

<canvas id = "myCanvas" height = "300" width = "500" style = "border:2px solid #808080;"></canvas>

On adding a function for button and clicking on it, you won’t be able to get what you want −

<div>
   <input type = "button" value = "Submit" onclick = "submit()">
</div>

You will not be able to get those values from the canvas since the canvas is just a bitmap.

Updated on: 24-Jun-2020

260 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements