javascript - canvas todataurl corrupted images -


i have app allow users sign document, drawing sign in canvas.

function initialize(xsize, ysize) {          // references canvas element 2d drawing context          sigcanvas = document.getelementbyid("canvassignature");          sigcanvas.width = xsize;          sigcanvas.height = ysize;          var context = sigcanvas.getcontext("2d");          context.strokestyle = 'black';          // defined on touch device such ipad or android, etc.          var is_touch_device = 'ontouchstart' in document.documentelement;           if (is_touch_device) {             // create drawer tracks touch movements             var drawer = {                isdrawing: false,                touchstart: function (coors) {                   context.beginpath();                   context.moveto(coors.x, coors.y);                   this.isdrawing = true;                },                touchmove: function (coors) {                   if (this.isdrawing) {                      context.lineto(coors.x, coors.y);                      context.stroke();                   }                },                touchend: function (coors) {                   if (this.isdrawing) {                      this.touchmove(coors);                      this.isdrawing = false;                   }                }             }; 

then use todataurl image canvas , save in local storage.

function save_canvas(index) {            sigcanvas = document.getelementbyid("canvassignature");           var img = sigcanvas.todataurl('image/jpeg');            window.localstorage.setitem("fm"+ index, img);           sigcanvas.width = sigcanvas.width;       } 

now export sign in pdf using jspdf. should use jpeg images on png i'm using todataurl('image,jpeg'). when retake image localstorage,

function firma(titlenum) {     canvasnum = titlenum;     xcoord = (window.event.clientx-50);     ycoord = (window.event.clienty-50);     idsign = "fm" + titlenum;     var img_firma = window.localstorage.getitem(idsign);     if (null != img_firma && img_firma != "") {         alert(img_firma);         $('#pagesign').hide();         $('#pagesignimg').show();          var toappend = new image;         toappend.title = 'firma';         toappend.src = img_firma;         toappend.classname = "imgfirma";         $('#div_firmaimg').empty();         document.getelementbyid('div_firmaimg').appendchild(toappend);         document.getelementbyid('signnascosteimg').click();     } else {         alert(img_firma);         $('#pagesign').show();          $('#pagesignimg').hide();         initialize(0, 0);         document.getelementbyid(idsign).classname = "editsign";         document.getelementbyid('signnascoste').click();     }    } 

the base64 results corrupted this:

data:image/jpeg;base64,/9j/4aaqskzjrgabaqaaaqabaad/2wbdaaicagicaqicagicagidawyeawmdawcfbqqgcacicaghcagjcg0lcqkmcggicw8lda0odg4ocqsqeq8oeq0odg7/2wbdaqicagmdawyebayocqgjdg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg4odg7/waarcakgbradasiaahebaxeb/8qahwaaaqubaqebaqeaaaaaaaaaaaecawqfbgcicqol/8qatraaagedawieawufbaqaaaf9aqidaaqrbrihmuege1fhbyjxfdkbkaeii0kxwrvs0fakm2jyggkkfhcygroljicokso0nty3odk6q0rfrkdisuptvfvwv1hzwmnkzwznaglqc3r1dnd4exqdhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2uhi4+tl5ufo6erx8vp09fb3+pn6/8qahweaawebaqebaqebaqaaaaaaaaecawqfbgcicqol/8qatreaagecbaqdbacfbaqaaqj3aaecaxeebsexbhjbuqdhcrmimoeifekrobhbcsmzuvavynlrchyknoel8rcygromjygpkju2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6gooehyahiimkkpoulzaxmjmaoqokpaanqkmqsro0tba3ulm6wspexcbhymnk0tpu1dbx2nna4upk5ebn6onq8vp09fb3+pn6/9oadambaairaxeapwd+f+iiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooakkkkaciiigaooooak 

i can't understand why....


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -