【发布时间】:2022-07-21 04:17:35
【问题描述】:
目前,我正在尝试从 <video> 拍摄快照,预览分辨率为 320*420。我想加倍 res 所以结果会更大。当尝试调整大小时,结果是模糊的。我应该实现任何库吗?
HTML
<style>
#videoframe{
border: 10px solid black;
height:320px;
margin-bottom:20px;
width:420px;
padding:0;
overflow:hidden;
position:relative;
}
</style>
<div class="col-lg-6" id="videoframe">
<video style="margin:0;width: 100%; height:100%;" id="player" webkit-playsinline="true" autoplay playsinline>
</video>
</div>
<canvas id="c" width="320"height="420" ></canvas>
JS
function imageToDataUri(img, width, height) {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);
return canvas.toDataURL('image/png', 1.0);
}
$("#btnCapture").click(function () {
videoPlayer.pause();
var canvas = document.getElementById("c")
var ctx = canvas.getContext('2d');
ctx.drawImage(videoPlayer, 0,0 ,320, 420);
image = canvas.toDataURL('image/png',1.0);
//Resize
var img = new Image;
img.onload = resizeImage;
img.src = image;
function resizeImage() {
var newDataUri = imageToDataUri(this, 640, 840);
//NewDataUri is final result
}
});
【问题讨论】:
-
为什么
ctx.drawImage(videoPlayer, 0,0 ,320, 420);不能画大一点?
标签: canvas html5-video video-capture image-resizing