简体   繁体   English

获取隐藏视频的高度和宽度

[英]get height and width of hidden video

I have tried: 我努力了:

video.height // never worked
video.offsetHeight // worked when video was visible, now returning 0

for the purpose of showing only a processed video, I keep the video element hidden, and if I am drawing it on the screen in certain intervals, the below code works(even witht eh video hidden), 为了仅显示已处理的视频,我将视频元素保持隐藏状态,如果我按特定的时间间隔在屏幕上绘制它,则以下代码有效(即使隐藏了视频),

var video = document.getElementById('someVid');
var canvas = document.getElementById('someCanvas');
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.height, canvas.width);

I need the height and width for some processing, before drawing, so the new draw line would be: 在绘制之前,我需要进行一些高度和宽度的处理,因此新的绘制线将是:

ctx.drawImage(video, x, y, w, h, 0, 0, canvas.height, canvas.width);

for calculation of that x,y,w,h I need hidden video's height, width. 为了计算x,y,w,h我需要隐藏视频的高度,宽度。

ps: no need IE support, only firefox and chrome. ps:不需要IE支持,只有Firefox和chrome。

ok, found the solution, 好,找到解决方案,

var height = video.videoHeight;
var width =  video.videoWidth;

returns intrinsic values... 返回内在值...

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM