简体   繁体   中英

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.

ps: no need IE support, only firefox and chrome.

ok, found the solution,

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

returns intrinsic values...

source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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