因此,我在播放OGG视频的HTML 5页面上具有简单的视频标签.我想将其RGB颜色设置为数组格式(假设我们知道宽度和高度),以限制每个像素(从像素1,1到maxWidth,maxHeight)的颜色,例如{{R:Color,G:Color,B:Color},{R:Color,…}
最佳答案
您可以使用HTML5 Canvas元素的drawImage函数.
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#the-canvas-element
原文链接:https://www.f2er.com/html/530651.htmlhttp://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#the-canvas-element
基本上,您可以创建一个与视频大小相同的画布.
然后,使用canvas.getContext(“ 2d”);获取画布的上下文.
调用上下文的drawImage(sourceVideo,dx,dy)函数. dx和dy都应为0.
然后,通过context.getImageData(sx,sy,w,h);获取画布的图像数据.
将上述图像数据存储到变量中,我将其称为id.
您的pixeldata数组以以下格式存储在id.data中:
`[r,g,b,a,r,a …等]
var canvas = document.createElement("canvas");
canvas.width = video.width;
canvas.height= video.height;
var context= canvas.getContext("2d");
context.drawImage(sourceVideo,0);
var id = context.getImageData(0,video.width,video.height);
for(var y = 0; y < video.height; y++)
{
for(var x = 0; x < video.width; x++)
{
//r = id.data[y*video.width + x + 0]
//g = id.data[y*video.width + x + 1]
//b = id.data[y*video.width + x + 2]
//a = id.data[y*video.width + x + 3]
}
}
希望有帮助!