javascript 无需画布即可将图像转换为 base64
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19310997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert image to base64 without canvas
提问by sachin
I need to convert an image to base64 encoding. I know its very easy with canvas. but the problem is that it should also run in IE8. but IE8 dont support HTML5 so i can't do it using canvas. Is there any other method using javaScript to convert image to base64 ?
我需要将图像转换为 base64 编码。我知道用画布很容易。但问题是它也应该在 IE8 中运行。但是 IE8 不支持 HTML5,所以我不能使用画布来做到这一点。有没有其他方法使用 javaScript 将图像转换为 base64 ?
Thanks
谢谢
回答by gurvinder372
There are some answers given here
这里给出了一些答案
How can you encode a string to Base64 in JavaScript?
如何在 JavaScript 中将字符串编码为 Base64?
have you tried any of them?
你试过其中任何一个吗?
回答by gurvinder372
Simple answer is no if this needs to be done on client side. The canvas element is the only way to convert an image to bitmap data or data-uris (and even then security restriction may apply preventing this).
如果这需要在客户端完成,简单的答案是否定的。canvas 元素是将图像转换为位图数据或数据 uri 的唯一方法(即使如此,安全限制也可能会阻止这种情况发生)。
You can maybe get around this using Flash but of course that would require the client to have Flash installed.
您也许可以使用 Flash 来解决这个问题,但这当然需要客户端安装 Flash。
Or setting up an external web service where you can upload the image and have it return the data you need.
或者设置一个外部网络服务,您可以在其中上传图像并让它返回您需要的数据。
For IE8 and lower there are no options out of the box (exCanvas gives you canvas drawing capabilities but can't provide bitmap data which is needed here). Basically, for IE8 you will need a server.
对于 IE8 及更低版本,没有开箱即用的选项(exCanvas 为您提供画布绘图功能,但无法提供此处所需的位图数据)。基本上,对于 IE8,您将需要一个服务器。