如何使用javascript图像转换成字符串的base64

如何使用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).