我需要用我的网络摄像头拍摄一张快照,并将拍摄的照片作为文件保存到<input type="file">
我设法使用webcam.js
.
现在我需要将我的输入文件设置为我刚刚拍摄的快照。
我如何拍摄快照:
HTML:
<input type=button value="Take Snapshot" onClick="take_snapshot()">
JS:
function take_snapshot() {
// take snapshot and get image data
Webcam.snap( function(data_uri) {
// display results in page
document.getElementById('results').innerHTML =
'<h2>Here is your image:</h2>' +
'<img src="'+data_uri+'"/>';
} );
}
在 JS 中,这data_uri
是我刚刚拍摄的快照的 base64。
有没有办法使用 base64 字符串作为我的输入文件<input type="file">
?