[英]how to edit snapshot from a video?
我正在通過getUserMedia從計算機加載視頻,並使用畫布拍攝快照。 但是,當我嘗試編輯下面的代碼時,我無法。
var canvas = document.querySelector("canvas")
var ctx = canvas.getContext('2d');
var sketch = document.getElementById("sketch")
var sketch_style = getComputedStyle(sketch)
canvas.width = parseInt(sketch_style.getPropertyValue('width'))
canvas.height = parseInt(sketch_style.getPropertyValue('height'))
var mouse = {x: 0, y: 0}
var last_mouse = {x: 0, y: 0}
/* Mouse Capturing Work */
canvas.addEventListener('mousemove', function(e) {
last_mouse.x = mouse.x;
last_mouse.y = mouse.y;
mouse.x = e.pageX - this.offsetLeft;
mouse.y = e.pageY - this.offsetTop;
}, false);
/* Drawing on Paint App */
ctx.lineWidth = 5;
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
/* Posso fazer um switch case aqui pra escolher uma cor */
ctx.strokeStyle = 'blue';
canvas.addEventListener('mousedown', function(e) {
canvas.addEventListener('mousemove', onPaint, false);
}, false);
canvas.addEventListener('mouseup', function() {
canvas.removeEventListener('mousemove', onPaint, false);
}, false);
var onPaint = function() {
ctx.beginPath();
ctx.moveTo(last_mouse.x, last_mouse.y);
ctx.lineTo(mouse.x, mouse.y);
ctx.closePath();
ctx.stroke();
};
function snapshot() {
canvas.width = 500;
canvas.height = 300;
ctx.drawImage(videoNode, 0, 0, canvas.width, canvas.height);
}
foto.addEventListener('click', snapshot, false);
我可以放線,但它們不會改變顏色,粗細等。我正在使用Electron來執行桌面Web應用程序。 有人能幫我嗎?? :D
這是因為當您設置新大小時-即使大小相同,畫布也會重置狀態。 可以在設置新大小后通過設置行內容來固定
function snapshot() {
canvas.width = 500;
canvas.height = 300;
ctx.drawImage(videoNode, 0, 0, canvas.width, canvas.height);
// set line stuff here <=====================
ctx.lineWidth = 5;
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
/* Posso fazer um switch case aqui pra escolher uma cor */
ctx.strokeStyle = 'blue';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.