【已解决】canvas跨域问题
var img = new Image(); // 关键点,设置crossOriginal属性 img.setAttribute('crossOrigin', 'anonymous'); var canvas = document.getElementById("canvas"); var ctx = canvas.getContext('2d'); img.onload = function () { canvas.width = img.width; canvas.height = img.height + 200; ctx.drawImage(img, 0, 0); document.getElementById('canvasImg').src = canvas.toDataURL("image/jpeg", 1); } img.src = 'http://img.hb.aicdn.com/38d8f519b3f464a80d85ed9632fed904ed0181f41d632-ZHrigO_fw658';
关键的代码是:
img.setAttribute('crossOrigin', 'anonymous');
本文来自博客园,作者:沉迷编程的程序员,转载请注明原文链接:https://www.cnblogs.com/codeDevotee/p/12296495.html
欢迎各位找我代写程序,python、c#、web等都可以,加我请注明博客园微信:A15919195482