fex-team.github.io icon indicating copy to clipboard operation
fex-team.github.io copied to clipboard

canvas 调用toDataUrl 报污染的画布无法导出

Open baby2011 opened this issue 7 years ago • 2 comments

baby2011 avatar Apr 18 '18 01:04 baby2011

你好,我在看http://fex.baidu.com/blog/2015/11/convert-svg-to-png-at-frontend/ 这篇文章的时候发现canvas 调用toDataUrl 报污染的画布无法导出错误,请问如何解决呢?图片资源响应头设置了cors也不行

baby2011 avatar Apr 18 '18 01:04 baby2011

@baby2011 将 imgcrossOrigin 设置为 anonymous

const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
  // draw img
};
img.src = 'http://example.com/image';

https://developer.mozilla.org/zh-CN/docs/Web/HTML/CORS_enabled_image

xiaosongxiaosong avatar Sep 18 '18 08:09 xiaosongxiaosong