【发布时间】:2020-08-16 18:09:10
【问题描述】:
我正在尝试对相机网站进行编程。流似乎可以工作,我可以看到画布在绘制时捕获了它的图像,但是在将其更改为图像然后下载它时,我似乎遇到了问题。求救
function capture() {
var canvas = document.getElementById('canvas');
var video = document.getElementById('video');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 140, 0, video.videoWidth, video.videoHeight);
var data = canvas.toDataURL();
var prev = window.location.href;
window.location.href = data.replace("image/png", "image/octet-stream");
window.location.href = prev;
【问题讨论】:
-
能否确保您提供的代码足以让我们调试问题?了解如何制作minimal reproducible example。
-
这个link 可能有用。在您的情况下,您需要设置
a.href = canvas.toDataURL();此更改与上述链接中的代码进行比较
标签: javascript jquery