问题描述
我是javascript和html5的新手.我正在做我的大学项目.我正在创建一个基于Web的照片捕获系统.是否可以自动将图像保存到本地存储.用户按下捕获"按钮之后?
I'm new to javascript and html5. I'm doing my college project. I'm creating a web-based photo capturing system. Is it possible to automatically save the image to local storage. After user had hit on the capture button?
仅供参考,当用户点击捕获按钮时,它将激活该功能
FYI,when the user hit on capture button, it active this function
function(){context.drawImage(video,0,0,320,240)}
谢谢.
推荐答案
您可以使用 toDataURL 生成一个< a>
链接,该链接将允许用户下载图像:
You can use toDataURL to generate an <a>
link which would allow the user to download the image:
function(){
context.drawImage(video, 0, 0, 320, 240);
var dl = document.createElement("a");
dl.href = canvas.toDataURL();
dl.innerHTML = "Download Image!";
dl.download = true; // Make sure the browser downloads the image
document.body.appendChild(dl); // Needs to be added to the DOM to work
dl.click(); // Trigger the click
}
然后应开始下载映像.这依赖于浏览器对 download
属性的支持.
This should then initiate the download of the image. This relies on browser support of the download
attribute.
这篇关于自动将图像保存到本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!