I am using this code to display data of two canvas into third canvas but it is not working. I am saving the two canvas data using localstorage and passing it to third canvas
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); //First canvas data var img1 = loadImage(localStorage.getItem('cbdata'), main); //Second canvas data var img2 = loadImage(localStorage.getItem('cbdata1'), main); var imagesLoaded = 0; function main() { imagesLoaded += 1; if (imagesLoaded == 2) { // composite now ctx.drawImage(img1, 0, 0); ctx.globalAlpha = 0.5; ctx.drawImage(img2, 0, 0); } } function loadImage(src, onload) { var img = new Image(); img.onload = onload; img.src = src; return img; }
localStorage["cddata"]and is that data the correct format?canvashas been created. Move the script block at the end of the page, just before the closing</body>tag.