[英]Canvas to blob on Edge
Getting exception on Microsoft Edge browser when trying to convert Html canvas element to blob.尝试将 Html 画布元素转换为 blob 时,在 Microsoft Edge 浏览器上出现异常。 Everything works great on normal browsers.
在普通浏览器上一切正常。 Exception:
例外:
SCRIPT438: Object doesn't support property or method 'toBlob'
SCRIPT438:对象不支持属性或方法“toBlob”
Html snippet: html片段:
<canvas id="cnv" width="640px" height="520px" style="display: none"></canvas>
Javascript: Javascript:
var files[];
var canvas = document.getElementById('cnv');
canvas.toBlob(function (blob) {
files.push(blob);
}
}, 'image/jpeg', 1);
I get this exception right when I call toBlob
method.当我调用
toBlob
方法时,我得到了这个异常。 Are there any ways to teach Edge blob converting?有什么方法可以教 Edge Blob 转换吗? I am using :
我在用 :
Microsoft Edge 41.16299.15.0
微软边缘 41.16299.15.0
This small polyfill taken from here must help see jsfiddle取自这里的这个小polyfill必须有助于查看 jsfiddle
if (!HTMLCanvasElement.prototype.toBlob) {
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function (callback, type, quality) {
var canvas = this;
setTimeout(function() {
var binStr = atob( canvas.toDataURL(type, quality).split(',')[1] ),
len = binStr.length,
arr = new Uint8Array(len);
for (var i = 0; i < len; i++ ) {
arr[i] = binStr.charCodeAt(i);
}
callback( new Blob( [arr], {type: type || 'image/png'} ) );
});
}
});
}
This could help as well github.com/blueimp/JavaScript-Canvas-to-Blob这也有帮助github.com/blueimp/JavaScript-Canvas-to-Blob
If you use webpack and ES6 then install the package via npm如果你使用webpack和ES6然后通过 npm安装包
npm install blueimp-canvas-to-blob
Then import the package like so然后像这样导入包
import "blueimp-canvas-to-blob/js/canvas-to-blob";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.