Canvas Image Cropper - Canvas.todataurl Is Acting Asynchronously Does This Return Any Kind Of Promise
If I put an alert between 'toDataURL' and a canvas draw using the result then everything proceeds as expected. Does toDataURL fire an event on the canvas or should I use some kind
Solution 1:
.toDataURL
is a synchronous operation that does not trigger any events.
Being synchronous, it's a blocking operation so no alert
is required to prevent the next command from executing before toDataURL is fully complete. The next command will execute when toDataURL is fully complete.
Since you're using the dataURL as an image source, you will want to give that image time to load by assigning a callback:
var img=newImage();
img.onload=function(){
ctx.drawImage(img,0,0);
}
img.src=canvas.toDataURL();
Solution 2:
.toDataURL is a synchronous operation that does not trigger any events. This is not true anymore for Chrome 57. Not sure if this is a bug or on purpose.
Post a Comment for "Canvas Image Cropper - Canvas.todataurl Is Acting Asynchronously Does This Return Any Kind Of Promise"