項目有一個類似美圖秀秀的功能劝篷,存放在本地時能對圖片正常編輯巴粪,考慮到圖片量大通今,用了阿里云oss
但是出現(xiàn)了錯誤:Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.at Image.img.onload
于是百度查閱資料,太多同類文章验毡,有需要還是上Google好些
解決方法:
var timestamp =new Date().getTime();
img.setAttribute('crossOrigin', 'anonymous');
img.src = url +'?' + timestamp;
參考:https://stackoverflow.com/questions/20424279/canvas-todataurl-securityerror/27260385#27260385