题目描述
有没有人碰到这样的问题
canvas.toDataURL失败,报错tainted canvases may not be exported.
1、图片已经设置了crossorigin="anonymous"
2、图片只要不使用CSS3滤镜的svg滤镜(例如filter:url(filter.svg#warm))就不存在错误
相关代码
let canvas:HTMLCanvasElement = document.createElement('canvas');
canvas.width = this.img.width;
canvas.height = this.img.height;
// let dpr = this.getDPR();
let context = canvas.getContext('2d');
(context as any).filter = window.getComputedStyle(this.imgDom).filter;
console.log(window.getComputedStyle(this.imgDom).filter);
context.drawImage(this.img, 0, 0, canvas.width, canvas.height);
let aryURL = canvas.toDataURL("image/jpeg").split(",");
let mine = aryURL[0].match(/:(.*?);/)[1];
let dataUrl = new Blob([toByteArray(aryURL[1])], {type: mine});