用于下载 HTML5 Canvas 图像的立即保存对话框 - 不保存在服务器上
我正在开发一个纯 JS/HTML 页面,用户可以上传图像,图像将转换为画布数据并显示。然后,用户可以单击按钮来对像素数据进行更改,从而更改显示。
现在,如果用户想要保存图像,他们可以右键单击并另存为,系统会提示他们将图像另存为 canvas.png;然而,我更希望只有一个“下载图像”按钮,用户可以单击该按钮来弹出标准保存对话框。
我的问题是如何制作这样一个按钮,将画布数据拉入标准图像下载提示?
以下是更多详细信息:
如果您在显示的图像上执行“查看图像”,则其转到的 url 如下所示: data:image/png;base64,iVBORw0KGgoAA(还有更多东西)
I am working on a purely JS/HTML page where the user can upload an image and the image is converted to canvas data and displayed. Then the user can click on a button to have alterations performed to the pixel data, changing the display.
Now, if the user wants to save the image they can right click and do a save as and they are prompted to save the image as canvas.png; I would prefer, however, to just have a button "download image" that the user can click to pop up the standard save dialogue box.
My question is how can make such a button, that pulls the canvas data into a standard image download prompt?
Here are some more details:
If you do a "view image" on the displayed image the url it goes to is like this:
data:image/png;base64,iVBORw0KGgoAA (lots more stuff)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Jacob Seidelin 创建了一个库,允许您将画布保存为图像。您可以在此处找到他的网站!
Jacob Seidelin, has created a library that allows you to save the canvas as an image. You can find his site here!