图片canvas跨域问题解决方案之一
let image = new Image(); image.src = src + '?v=' + Math.random(); image.crossOrigin = 'Anonymous'; // 支持跨域图片 image.onload = function() { let canvas = document.createElement('canvas'); canvas.width = image.width; canvas.height = image.height; let ctx = canvas.getContext('2d'); ctx.drawImage(image, 0, 0, image.width, image.height); canvas.toDataURL('image/png'); // 可选其他值 image/jpeg };
图片使用代码中方式插入