画布在边缘上斑点

uvy*_*tas 10 javascript html5 blob html5-canvas microsoft-edge

尝试将Html canvas元素转换为blob时在Microsoft Edge浏览器上获取异常.一切都适用于普通浏览器.例外:

SCRIPT438:对象不支持属性或方法'toBlob'

Html代码段:

<canvas id="cnv" width="640px" height="520px" style="display: none"></canvas>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var files[];
var canvas = document.getElementById('cnv');
canvas.toBlob(function (blob) {            
        files.push(blob);
         }
    }, 'image/jpeg', 1);
Run Code Online (Sandbox Code Playgroud)

当我调用toBlob方法时,我得到了这个异常.有没有办法教Edge gb转换?我在用 :

Microsoft Edge 41.16299.15.0

isA*_*lex 18

从这里取出的这种小型填充物必须有助于看到j​​sfiddle

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'} ) );
       });
     }
  });
}
Run Code Online (Sandbox Code Playgroud)

这也有助于github.com/blueimp/JavaScript-Canvas-to-Blob