如何使用javascript图像转换成字符串的base64 [英] How to convert image into base64 string using javascript

查看:100
本文介绍了如何使用javascript图像转换成字符串的base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的图像转换成一个base64字符串,这样我可以把我的形象到服务器。
对此有任何的js文件...?否则如何将它转换

I need to convert my image to a base64 string so that i can send my image to a server. Is there any js file for this... ? Else how to convert it

推荐答案

您可以使用HTML5 <&帆布GT; 吧:

You can use the HTML5 <canvas> for it:

创建一个画布,你的图像加载到它,然后使用 toDataURL() 得到的base64再presentation(实际上,这是一个数据: URL但它包含的base64恩codeD映像)

Create a canvas, load your image into it and then use toDataURL() to get the base64 representation (actually, it's a data: URL but it contains the base64-encoded image).

这篇关于如何使用javascript图像转换成字符串的base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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