三星浏览器中摄像头问题的javascript画布截图
嗯,我有一个非常奇怪的问题,只发生在三星浏览器上。在Chrome和其他浏览器上,这很有效 当我在javascript上拍摄当前视频帧(当前是移动摄像机)的快照时,我得到的图像失真且通常不好 获取快照的代码是:三星浏览器中摄像头问题的javascript画布截图,javascript,html5-canvas,samsung-browser,Javascript,Html5 Canvas,Samsung Browser,嗯,我有一个非常奇怪的问题,只发生在三星浏览器上。在Chrome和其他浏览器上,这很有效 当我在javascript上拍摄当前视频帧(当前是移动摄像机)的快照时,我得到的图像失真且通常不好 获取快照的代码是: function takeSnapshot() { // Here we're using a trick that involves a hidden canvas element. video.pause(); var hid
function takeSnapshot() {
// Here we're using a trick that involves a hidden canvas element.
video.pause();
var hidden_canvas = document.createElement('canvas'),
context = hidden_canvas.getContext('2d');
var width = video.videoWidth,
height = video.videoHeight;
if (width && height) {
// Setup a canvas with the same dimensions as the video.
hidden_canvas.width = width;
hidden_canvas.height = height;
// Make a copy of the current frame in the video on the canvas.
context.drawImage(video, 0, 0, width, height);
// Turn the canvas image into a dataURL that can be used as a src for our photo.
return hidden_canvas.toDataURL('image/jpeg');
}
}
在三星浏览器中,我是否缺少其他功能?或者我只是放了一条消息说这与此浏览器不兼容?
目前在三星Galaxy S9和安卓10上进行测试
-------------更新
我发现是什么导致图像被拍得不好。
我使用自定义大小的图像,在本例中,是一个水平矩形。
我在初始化视频时会这样做:
var w = 2000; // This renders the video as a horizontal rectangle, this does the issue.
var h = 1200;
var userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || '';
var isSamsungBrowser = userAgent.indexOf('SamsungBrowser') >= 0;
// Quick fix:
if(SamsungBrowser){ // If I render as vertical renctangle, the issue is gone.
w = 1200;
h = 2000;
}
navigator.getMedia(
{
video:
{
deviceId: videoSource ? { exact: videoSource } : undefined,
width: { ideal: h },
height: { ideal: w }
}
},
// Success Callback
function (stream) {
// Create an object URL for the video stream and
// set it as src of our HTLM video element.
try {
currentStream = stream;
video.srcObject = stream;
} catch (error) {
video.src = window.URL.createObjectURL(stream);
}
window.stream = stream;
// Play the video element to start the stream.
video.play();
video.onplay = function () {
showVideo();
};
}
我不知道三星浏览器,但您是否检查过浏览器中是否完全支持
drawImage
?你的代码是好的,好吧,不需要暂停视频,你可以尝试没有它顺便说一句。至于问题,听起来更像是一个错误的视频编码器。您可以尝试使用,它显然是受支持的。Ps:无法在我的S6三星互联网v12.1.2.5上重新编程谢谢,我检测到了检测到的问题,但无法解决。我将编辑问题。我不知道三星浏览器,但您是否检查过浏览器中是否完全支持drawImage
?你的代码是好的,好吧,不需要暂停视频,你可以尝试没有它顺便说一句。至于问题,听起来更像是一个错误的视频编码器。您可以尝试使用,它显然是受支持的。Ps:无法在我的S6三星互联网v12.1.2.5上重新编程谢谢,我检测到了检测到的问题,但无法解决。我将编辑这个问题。