javascript - save image to canvas then draw more -



javascript - save image to canvas then draw more -

im trying save image canvas draw more. got soo far. spits out both image , drawing deletes image when add together text

-

draw image

var tctx2 = document.getelementbyid('textcanvas').getcontext('2d'), imageelem = document.getelementbyid('image'); var tctx = document.getelementbyid('textcanvas').getcontext('2d'), imageelem = document.getelementbyid('image'); var ttyl = document.getelementbyid('newimg'); tctx2.drawimage(ttyl,0,0); imageelem.src = tctx2.canvas.todataurl("images/image.png");

start text drawing

document.getelementbyid('text').addeventlistener('keyup', function (){ tctx.globalcompositeoperation="source-over"; var mytxt = document.getelementbyid('text').value; var mystr1 = mytxt.substr(0, 31); var mystr2 = mytxt.substr(31, 31); var mystr3 = mytxt.substr(62, 31); var mystr4 = mytxt.substr(93, 31); tctx.canvas.width = imageelem.width; tctx.fillstyle = '#000000'; tctx.font = '17pt "lucida sans unicode", "lucida grande", sans-serif'; tctx.filltext(mystr1, 10, 98); tctx.filltext(mystr2, 10, 122); tctx.filltext(mystr3, 10, 146); tctx.filltext(mystr4, 10, 168);

start saving together

var copiedimg = new image(); copiedimg.onload = function(){ tctx.drawimage(copiedimg, 0, 0); }; copiedimg.src = imageelem.src; imageelem.src = tctx.canvas.todataurl('image/png') }, false);

i have feeling it's line:

tctx.canvas.width = imageelem.width;

from here:

when assign value width or height poperties through javascript has side effect of resetting canvas. clearrect function means canvas returned transparency.

javascript canvas html5-canvas

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -