我正在尝试调整canvas DOM元素中相机显示的大小。我尝试过使用事件侦听器,并且能够毫无问题地调整画布的大小。然而,摄像机的视频源不会更新其大小,保持与初始化时的大小相同。为了让它工作,我基本上必须销毁大部分的合成,然后在每次窗口大小调整发生时重新初始化整个东西。它是有效的,但它很丑陋。有没有人有更好的解决方案?也许有一种方法可以让这个更优雅?感谢您的任何意见。
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize() {
// seriously
reformat = null
source = null
target.destroy()
target = null
seriously = new Seriously();
canvas.width = window.innerWidth * devicePixelRatio;
canvas.height = window.innerHeight * devicePixelRatio;
var source = seriously.source('camera');
target = seriously.target('#canvas');
reformat = seriously.transform('reformat');
reformat.source = source;
reformat.width = canvas.width;
reformat.height = canvas.height;
target.source = reformat
seriously.go(function(now) {
var minutes;
minutes = now / 6000;
console.log("running")
// split.angle = (minutes - Math.floor(minutes)) * PI2;
// split.split = Math.cos(now / 1000) / 2 + 0.5;
});发布于 2017-01-23 04:00:22
在迭代了每一个认真的例子之后,我找到了一个简单的解决方案。
var devicePixelRatio = window.devicePixelRatio || 1;
function resize() {
target.width = window.innerWidth * devicePixelRatio;
target.height = window.innerHeight * devicePixelRatio;
reformat.width = target.width;
reformat.height = target.height;
}
window.onresize = resize;https://stackoverflow.com/questions/41786654
复制相似问题