html - Canvas 到图像 : how to keep proportions

标签 html canvas webcam

这是我的测试代码:http://jsfiddle.net/Zx4fg/

为什么圆在 Canvas 上看起来像椭圆?

我想将网络摄像头的快照保存为图像,但生成的图像不符合比例。

我的真实代码是:

ctx.drawImage(video,0,0, 300, 150); // 300х150 - with this prop. image 
                                    //from webcam on canvas with true proportions
$('body').append($('<img>').attr('src', canvas.toDataURL()));

我变得像这样:

最佳答案

问题出在 Canvas 样式中,您应该在 HTML 中设置其宽度和高度属性。不在 CSS 中

<canvas id="canvas" width="320" height="2400" style="border:1px solid #d3d3d3;">

关于html - Canvas 到图像 : how to keep proportions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234568/

相关文章:

java - 如何查找系统是否已连接网络摄像头

javascript - 如何在 Raspberry PI 上流畅地运行 HTML、CSS 和 JS 视频

javascript - EaselJS onclick 接管整个 Canvas

javascript - 将 HTML5 Canvas + Javascript 应用程序转换为可执行文件

javascript - 使用 Fabric.js 绘制贝塞尔曲线

javascript - 在 Firefox 上使用 HTTPS 时强制 getUserMedia 重新提示

带 2 个摄像头的 OpenCV VC++

javascript - 无法解析模块说明符 "firebase/app"

java - 在 GWT 中为不同页面使用元标记?

javascript - CSS:如果表头悬停,如何在表的每个单元格上触发悬停?