Javascript Canvas:调整大小和重新采样后base64返回到文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6609111/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:15:56  来源:igfitidea点击:

Javascript Canvas: base64 back to file after resizing&resampling?

javascripthtmlcanvas

提问by Somebody

Possible Duplicate:
Convert Data URI to File then append to FormData

可能的重复:
将数据 URI 转换为文件,然后附加到 FormData

Is it possible to save rendered canvas back to a file in Google Chrome?

是否可以将渲染的画布保存回 Google Chrome 中的文件?

I have tried this:

我试过这个:

canvas.getAsFile('foo.jpg','image/jpeg')

Doesn't work.

不起作用。

This works only in Firefox:

这仅适用于 Firefox:

canvas.mozGetAsFile('foo.jpg')

Of course I can and probably will just send raw base64 encoded string to server and decode it there.

当然,我可以而且可能只会将原始 base64 编码字符串发送到服务器并在那里对其进行解码。

But if it's possible to do it on client-side, i would prefer doing it there.

但是,如果可以在客户端进行,我更愿意在那里进行。

采纳答案by Sani Singh Huttunen

Maybe thisStack Overflow Question and Answer might help you.

也许这个堆栈溢出问题和答案可能对你有帮助。