Canvas toBlob无法识别为Chrome或IE中的函数 [英] Canvas toBlob is not recognized as a function in Chrome or IE

查看:2738
本文介绍了Canvas toBlob无法识别为Chrome或IE中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cropper获取裁剪图像的blob。我使用的最新版本的Chrome和IE,但我得到'canvas.toBlob不是一个函数'在Chrome和'对象不支持属性或方法'toBlob'在IE。似乎我正在跟踪文档,但我可能会缺少一些库或东西。
遵循文档这里和此主题来自SO 这里

I'm using Cropper to get the blob for a cropped image. I'm using the latest versions of Chrome and IE, but I'm getting 'canvas.toBlob is not a function' in Chrome and 'Object doesn't support property or method 'toBlob' in IE. Seems like I'm following the doc correctly but I might be missing some library or something. Following the doc here and this thread from SO here

有趣的是,我可以调用

var t = $("#imageToCrop").cropper('getCroppedCanvas').toDataURL();

它可以很好地返回数据,但toBlob似乎不工作。

and it works fine to return the data but toBlob doesn't seem to work.

这是我的JS和HTML。

Here is my JS and HTML.

var canvas = document.getElementById("imageToCrop");
canvas.toBlob(function(blob) {
  var t = blob;
});

<div style="width: 500px; height: 500px; display: table; margin: 0 auto;">
  <canvas id="imageToCrop" style="border: 1px solid black;" src=""></canvas>
</div>

我也尝试过下面但是看到相同的错误

I also tried this below but seeing the same errors

var t = $("#imageToCrop").cropper('getCroppedCanvas').toBlob();


推荐答案

目前, toBlob 仅在Firefox中完全支持 a>。 Internet Explorer有来自IE 10的部分支持,但它是供应商前缀,我假设是 msToBlob 。但是,至少有一个polyfill可用

Currently, toBlob is only fully supported in Firefox. Internet Explorer has partial support from IE 10, but it is vendor-prefixed to what I assume is msToBlob. There is however at least one polyfill available.

以下是Chrome和Safari的相关问题:

Here are the relevant issues for Chrome and Safari:

  • Chromium 67587 (Chrome)
  • WebKit 71270 (Safari)

由于某种原因,WebKit错误被标记为RESOLVED WONTFIX。

For some reason, the WebKit bug is marked as "RESOLVED WONTFIX".

这篇关于Canvas toBlob无法识别为Chrome或IE中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆