Software Archive
Read-only legacy content

toDataURL

Spiros_N_
Beginner
446 Views

Hi,

I toDataURL function supported on a canvas for a crosswalk deployment ?
Do I need plugin ?

this code:

var ctx = document.getElementById('avatarCanvas').getContext('2d');
ar img = new Image();
img.src = url;
img.onload = function () {
ctx.drawImage(img,0,0);
    
alert( ctx.toDataURL('image/png') );   

fails with "undefined" function

0 Kudos
3 Replies
Swati_S_Intel1
Employee
446 Views

toDataURL is supported on crosswalk. toDataURL works on the canvas element, I think in your code you are applying toDataURL on the context. 

Try doing this :

var canvas = document.getElementById('avatarCanvas');

alert( canvas.toDataURL('image/png') );

 

Swati

0 Kudos
Dale_S_Intel
Employee
446 Views
As Swati points out, toDataUrl is a property of a canvas element, not a canvas context. I think you should have code like this:
 
var el = document.getElementById('avatarCanvas');
var ctx = el.getContext('2d');
var img = new Image();
img.src = url;
img.onload = function () {
    ctx.drawImage(img,0,0);
   
    alert( el.toDataURL('image/png') );   
}

You may also have to deal with cross origin problems (e.g. "img.crossOrigin = true;") but this seemed to work for me.

 
0 Kudos
Spiros_N_
Beginner
446 Views

OK Thank you all for your help !

0 Kudos
Reply