<强度> 目标: 强度> 用 html5 和 JavaScript 对视频应用 CSS 过滤器 。
contraints: 解决方案 must 与 Internet Exporer 10 (Windows 8) 兼容。 我真的在做一个Metro 应用程序 。
So Far:
I have a <video>
that I am pumping onto a <canvas>
. I thought I would be able to apply CSS filters directly to this (e.g. invert
or brightness
) but it turns out those are not compatible with IE10.
Thoughts: 我希望能找到一种方法将 SVG 过滤器应用到画布上。 可能吗? 我是否需要将 复制到
中?
Thank you for all your help!
以下为感兴趣的人士提供守则:
过滤器. svg :
<?xml version="1.0" standalone="no"?>
<svg width="1" height="1" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="blur">
<feGaussianBlur in="SourceGraphic" stdDeviation="2 3" />
</filter>
</defs>
</svg>
样式. css:
.a {
filter: url(filter.svg#blur);
-ms-transform: matrix(-1, 0, 0, 1, 0, 0);
}
页面. html :
<div class="itemtemplate" data-win-control="WinJS.Binding.Template">
<canvas class="a" style="width: 180px;height:180px;margin-bottom: -5px;" data-win-bind="style.backgroundColor: bc; id: effectId" />
</div>
<html>
<head>
</head>
<body>
<svg id="svgroot" viewbox="0 0 800 800" width="800" height="800" preserveAspectRatio="xMidYMin">
<defs>
<filter id="myHueRotate">
<feColorMatrix type="hueRotate" values="270"/>
</filter>
</defs>
<image id="a" filter="url(#myHueRotate)" x="0" y="0" width="300" height="300" />
<image id="b" filter="url(#myHueRotate)" x="300" y="0" width="300" height="300" />
<image id="c" filter="url(#myHueRotate)" x="0" y="300" width="300" height="300" />
<image id="d" filter="url(#myHueRotate)" x="300" y="300" width="300" height="300" />
</svg>
<canvas id="canvas" height="300" width="300"></canvas>
<video id="vid" src="movie.m4v" height="300" width="300" style="display: none" autoplay/>
<script>
var ctx = document.getElementById( canvas ).getContext( 2d );
var img = new Image();
img.src = img.jpg ;
img.onload = function(){
//ctx.drawImage(img,0,0);
//var canvasImage = canvas.toDataURL("image/png");
//var svgImage = document.getElementById( a );
//svgImage.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", canvasImage);
draw();
}
img.load();
function draw(){
var ctx = document.getElementById( canvas ).getContext( 2d );
var vid = document.getElementById( vid )
ctx.drawImage(vid,0,0,300,300);
var canvasImage = canvas.toDataURL("image/png");
document.getElementById( a ).setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", canvasImage);
document.getElementById( b ).setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", canvasImage);
document.getElementById( c ).setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", canvasImage);
document.getElementById( d ).setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", canvasImage);
setTimeout(draw,40);
}
</script>
</body>
</html>