canvas.toDataURL()在不同的浏览器上创建不同的base64编码字符串 [英] canvas.toDataURL() creates different base64 encoded strings on different browsers

查看:759
本文介绍了canvas.toDataURL()在不同的浏览器上创建不同的base64编码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户需要相互传输数据(不能通过服务器)。我认为从这些数据渲染图像可能会很好,并让他们发送图像(二维码不会工作的各种原因)。

I have an application where users need to transmit data to each other (can't go through the server). I thought it might be nice to render an image from that data, and have them send that image (QR codes won't work for various reasons).

我来了< a href =https://github.com/mudcube/PNG-Storage =nofollow> accross this github repo 看起来很有前途,实现它,在这里

I came accross this github repo which looked promising, and implemented it, here.

问题是,出于各种原因,输出将有所不同不同的浏览器(和可能的OS)。自己试试。在不同的浏览器中编码各种消息,您将看到不同的base64编码结果。

The problem is, for various reasons, the output will be different for different browsers (and possibly OS's). Try it for yourself. Encode various messages in different browsers, and you'll see different base64 encoded results.

有什么好的解决方案吗?我可以实现第三方画布库吗?也许可以使用 FileReader.readAsDataURL()

Is there any good solution to this? Can I implement a third party canvas library? Maybe use FileReader.readAsDataURL()?

推荐答案

好吧,最后,我确实需要使用第三方图像处理库,不能依赖于浏览器的画布功能。 这是我的解决方案:)

Alright, in the end, I did have to use a 3rd party image processing library, and couldn't depend on the browser's canvas feature. Here's my solution :)

我建立在此图片处理库的顶部。

这篇关于canvas.toDataURL()在不同的浏览器上创建不同的base64编码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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