我试图弄清楚如何从电子应用程序本地保存图像(png)。
我使用以下方法从画布中提取图像:
my_canvas.toDataURL('image/png')
但我不确定如何将该文件本地保存到用户计算机。
或者,有没有办法让我只显示图像,以便他们可以右键单击以保存它(就像在普通浏览器中一样),因为我无法使其工作。
答案 0 :(得分:-4)
我不知道您尝试了什么,但创建类似的链接应该有效:<a href="[the data url]" download="[whateverfilename.ext]" target="_blank">
像这样:
<a href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQHEBISExEWFhUVFSEVExEVGRsUHRoeHR0iFhsjHx8kKCgjIyYxJxsXLT0iJikvNS46IyIzODMxODQ5Oi0BCgoKDg0OGxAQGzcjHSYtLTUtLSstLTU3Ny0rLTYuNy0rKy0tLSsrLy0tNS0tLSstLTc3Ly0rLSs1NS8tLS4rN//AABEIAGYAZgMBIgACEQEDEQH/xAAcAAEAAQUBAQAAAAAAAAAAAAAABwIDBAUGAQj/xAAyEAACAgECBAUDAgUFAAAAAAABAgADEQQhBQYSMRMiQVFxB2GBMkIUI5GhsTNSctHw/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAMBAgT/xAAbEQEBAQEAAwEAAAAAAAAAAAAAAQIRITFBEv/aAAwDAQACEQMRAD8AnGIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiJi3cRpoPS11an2Z1B/zAyolKOLBkEEe43lUBERAREQEREBERATl+c+dqeVwEx4uoZc16ZTgkdgzH9q5/cfvjMxedufqeXw1NRF2rK+ShfMEJ7Gwj9I9cdzIZ4drb9Tdc9gW1mcl9Sz9BLAbgHHYe2Nu2851rjrOes7jfNOt5gdl1F1irjI0+kDKgHsxHmP5Iz7TTXcJpKkrSM9x1Dc+u+feZbaoaSzOMhwOqkZLEDsRgHcZ74xPdZZkgglELec4yVB7fbvjJxt3k+1aZkV6OtuFsLdHfZRnzL4bHp+GQ7GSDyd9US/h1cRCoX/09Ym1ZycAOP2H79vicAukWnJ6iD/tJLdWfX2/pLOor/lMo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