Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将SVG过滤器应用于HTML5画布?_Html_Internet Explorer_Canvas_Svg_Windows Runtime - Fatal编程技术网

将SVG过滤器应用于HTML5画布?

将SVG过滤器应用于HTML5画布?,html,internet-explorer,canvas,svg,windows-runtime,Html,Internet Explorer,Canvas,Svg,Windows Runtime,目标:使用html5和JavaScript对视频应用CSS过滤器 限制:解决方案必须与Internet Exporer 10(适用于Windows 8)兼容。我真的在做地铁应用 到目前为止: 我有一个,我正在泵入一个。我原以为我可以直接将CSS过滤器应用于此(例如,反转或亮度),但事实证明这些过滤器与IE10不兼容 想法:我希望找到一种将SVG过滤器应用于画布的方法。这可能吗?是否需要将复制到并对其应用过滤器?或者,是否应该有一种方法将画布包装成 谢谢你的帮助! 下面是一些代码供感兴趣的人使用:

目标:使用html5和JavaScript对视频应用CSS过滤器

限制:解决方案必须与Internet Exporer 10(适用于Windows 8)兼容。我真的在做地铁应用

到目前为止: 我有一个
,我正在泵入一个
。我原以为我可以直接将CSS过滤器应用于此(例如,
反转
亮度
),但事实证明这些过滤器与IE10不兼容

想法:我希望找到一种将SVG过滤器应用于画布的方法。这可能吗?是否需要将
复制到
并对其应用过滤器?或者,是否应该有一种方法将画布包装成

谢谢你的帮助! 下面是一些代码供感兴趣的人使用:

filters.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>
page.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>

var ctx=document.getElementById('canvas').getContext('2d');
var img=新图像();
img.src='img.jpg';
img.onload=函数(){
//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”,画布图像);
draw();
}
img.load();
函数绘图(){
var ctx=document.getElementById('canvas').getContext('2d');
var vid=document.getElementById('vid')
ctx.drawImage(视频,0,0300);
var canvasImage=canvas.toDataURL(“image/png”);
document.getElementById('a').setAttributeNS('http://www.w3.org/1999/xlink“,“xlink:href”,画布图像);
document.getElementById('b').setAttributeNS('http://www.w3.org/1999/xlink“,“xlink:href”,画布图像);
document.getElementById('c').setAttributeNS('http://www.w3.org/1999/xlink“,“xlink:href”,画布图像);
document.getElementById('d').setAttributeNS('http://www.w3.org/1999/xlink“,“xlink:href”,画布图像);
设置超时(抽签,40);
}

首先,要阅读的文章:

请特别注意以下部分:

使用SVG,而不是VML

使用CSS3,而不是DX过滤器

在第二节中,他们提到:

DX过滤器与SVG过滤器效果不同,尽管两者都使用CSS属性名过滤器

第二条:

他们给出了一个具体的例子,说明了如何使用
invert
,但是,假设这是IE中的方法,我可以理解为什么它不容易找到,并且可能在您的情况下起作用,也可能不起作用。但css将是:

#yourTargetElement {
     filter: DXImageTransform.Microsoft.BasicImage(invert=1);
}
他们没有提到亮度,但提到了其他几个过滤器和转换,第一篇文章提到了使用SVG。更多详细信息(希望有帮助),请访问:

这看起来像密钥的第1部分:

过滤器通过filter属性以filter=“url(#filterId)”的形式应用于SVG元素,也可以作为CSS属性过滤器应用:url(#filterId)

这是第二部分:

有16种不同的过滤器原语

现在,我相信他们提到的16个是SVG的完整集合,但了解MS,也可能意味着:

  • 这是我们支持的16项,或
  • 这是我们发明的16款浏览器,以继续我们的主张,使IE标准兼容,SVG/MathML友好,但这比在任何其他浏览器中都要困难……因为我们可以做到
  • 或者,引用莉莉·汤姆林的话:“我们不在乎,我们不需要……我们是电话公司。”

    但是,假设MS最终意识到他们需要赶上,进一步阅读16个基本过滤器,假设您只需要将嵌入的SVG与过滤器放在正确的位置(
    defs
    ),并通过css调用它们。下面是他们的一个例子(我稍微修改和简化):

    带嵌入式SVG的HTML:
    
    
    CSS(他们使用JS使其动态化,所以要小心):
    
    #你的目标元素{
    过滤器:url(#过滤器图片);
    }
    

    我之所以要提醒它们看起来有多“简单”,是因为它们是通过js和一个交互表单添加样式的(也许你也有同样的想法),但我认为这与在DOM中调用脚本中的元素的风险相同,因为它找不到过滤器并抛出错误。因此,如果您希望保持简单(非动态)并且事情仍然不起作用,请确保尝试将过滤器/svg置于样式之上(即使这会导致闪烁)。

    而不是将
    的帧复制到
    (可以通过
    toDataURL()
    执行此操作)我建议首先尝试通过
    将画布或视频直接嵌入到SVG中,看看是否可以使用过滤器。但首先:您是否验证过IE10支持您想要的SVG过滤器,即使在静态图像上也是如此?不幸的是,IE9/10不支持
    @RobertLongson-IE10确实支持通过CSS调用SVG过滤器,因此这是有希望的。而IE9,正如它所承诺的那样,最终会赶上IE7和IE8。除非你的老板拒绝升级,否则它与IE7和IE8无关。读一下我在回答中引用的Ma Bell的话。除非我们作为开发者不再担心IE用户(我知道这很难),否则他们永远都会抓住我们,而这显然是4个主要的替代和更好的浏览器的另一个选择。我想知道InternetExplorer是不是故意的失误<代码>;)谢谢你的帮助,安东尼!我根据你的回答编辑了我的问题。我通常拍摄一段视频,每秒将其复制到画布上25次,将画布复制到数据url,然后将每个图像的src设置为该url。(然后将SVG应用于图像)。有更好的方法吗?这是非常缓慢的,即使是一个视频,我是霍皮人
    #yourTargetElement {
         filter: DXImageTransform.Microsoft.BasicImage(invert=1);
    }
    
    <div id="svg_wrapper">
    <svg xmlns="http://www.w3.org/2000/svg" id="svgroot" viewBox="0 0 800 533" preserveAspectRatio="xMidYMin">
        <defs>
         <filter id="filtersPicture">
                 <feComposite operator="arithmetic" k1="0" k2="1" k3="0" k4="0" 
                   in="SourceGraphic" in2="SourceGraphic" result="inputTo_6">
                 </feComposite>      
                 <feColorMatrix type="saturate" id="filter_6" values="2" 
                                data-filterId="6">
                 </feColorMatrix>
                 </filter>
       </svg>
      </div>
    
    <style type="text/css">
         #yourTargetElement{
                 filter:url(#filtersPicture);
          }
     </style>