图像转换为Base64在Firefox的JavaScript [英] Convert image to base64 javascript on firefox

查看:396
本文介绍了图像转换为Base64在Firefox的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换的图像是在网页为Base64过的Greasemonkey或Firefox的.xpi扩展。
我该怎么办呢?
我知道我有BTOA()函数,但我只能用字符串使用它,而不是用图像。
有点帮助在这里。
谢谢你。

I need to convert image that are in a webpage to base64 over greasemonkey or firefox .xpi extension. How can i do it? I know that i have btoa() function, but i only can use it with strings, not with images. Little help here. Thanks.

推荐答案

您可以使用画布元素,并用绘制图像的drawImage() 到它,然后用 toDataURL()来获得的base64 EN codeD映像。

You could use the canvas element and draw the image using drawImage() onto it, then use toDataURL() to get the base64 encoded image.

请参阅: https://developer.mozilla.org/en/html/canvas

这篇关于图像转换为Base64在Firefox的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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