SVG在页面中使用时,不会显示SVG中的图像元素。

问题描述:

我创建了一张SVG图像,它将多个图层合并在一起并对几张传统的PNG图像进行动画处理。如果我直接在浏览器中查看the image,事情就会像他们应该看到的一样(主要是,无论如何 - 看起来像在FireFox中存在混合问题,但这对另一个线程来说是一个问题)。但是,当我使用图像in a page - 无论是在img标记中还是在元素的背景中,都不会显示SVG中的image元素。SVG在页面中使用时,不会显示SVG中的图像元素。

如果我将一个固定的形状粘贴到SVG中,它就会显示出来,所以我知道SVG一般可以正常工作,但其中的图像从不出现。任何人都知道我在做什么错了?

下面是文本形式的SVG为便于参考:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="190" width="640"> 

<style type="text/css" > 
    <![CDATA[ 

    .lighten{ 
     mix-blend-mode:lighten; 
    } 

    .layer{ 

    } 

    ]]> 
</style> 

<!-- <rect width="640" height="190" fill="#9da99e" /> --> 
<image class="layer lighten" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/rays-bottom.png"> 
    <animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0 320 95" to="360 320 95" dur="79s" repeatCount="indefinite" /> 
    <animate attributeName="opacity" values="0.0;0.8;0.0" dur="13s" repeatCount="indefinite" /> 
</image> 
<image class="layer lighten" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/glyphs.png"> 
    <animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0 320 95" to="360 320 95" dur="97s" repeatCount="indefinite" /> 
    <animate attributeName="opacity" values="0.0;0.6;0.0" dur="17s" repeatCount="indefinite" /> 
</image> 
<image class="layer" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/compass.png" /> 
<image class="layer lighten" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/rays-top.png"> 
    <animateTransform attributeName="transform" attributeType="XML" type="rotate" from="360 320 95" to="0 320 95" dur="87s" repeatCount="indefinite" /> 
    <animate attributeName="opacity" values="0.0;0.6;0.0" dur="13s" repeatCount="indefinite" /> 
</image> 
<image class="layer" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/flare-back.png" /> 
<image class="layer lighten" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/flare-yellow.png"> 
    <animate attributeName="opacity" dur="60s" repeatCount="indefinite" 
     keytimes="0.00;0.04;0.06;0.08;0.12;0.14;0.15;0.16;0.17;0.18;0.10;0.23;0.24;0.25;0.28;0.32;0.33;0.34;0.35;0.36;0.37;0.38;0.39;0.40;0.41;0.46;0.47;0.48;0.49;0.50;0.54;0.55;0.56;0.57;0.58;0.60;0.61;0.62;0.63;0.64;0.66;0.68;0.70;0.72;0.74;0.75;0.76;0.77;0.18;0.80;0.86;0.87;0.88;0.89;0.90;0.92;0.93;0.94;0.94;0.98;1.00" 
     values="0.60;0.65;0.80;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.75;0.80;0.75;0.60;0.60;0.65;0.75;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.75;0.80;0.75;0.60;0.60;0.65;0.85;0.65;0.60;0.60;0.75;0.90;0.75;0.60;0.60;0.75;0.95;0.75;0.60;0.60;0.65;0.75;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60" 
    /> 
</image> 
<image class="layer lighten" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/flare-white.png"> 
    <animate attributeName="opacity" dur="60s" repeatCount="indefinite" 
     keytimes="0.00;0.04;0.06;0.08;0.12;0.14;0.15;0.16;0.17;0.18;0.10;0.23;0.24;0.25;0.28;0.32;0.33;0.34;0.35;0.36;0.37;0.38;0.39;0.40;0.41;0.46;0.47;0.48;0.49;0.50;0.54;0.55;0.56;0.57;0.58;0.60;0.61;0.62;0.63;0.64;0.66;0.68;0.70;0.72;0.74;0.75;0.76;0.77;0.18;0.80;0.86;0.87;0.88;0.89;0.90;0.92;0.93;0.94;0.94;0.98;1.00" 
     values="0.60;0.65;0.80;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.75;0.80;0.75;0.60;0.60;0.65;0.75;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60;0.75;0.80;0.75;0.60;0.60;0.65;0.85;0.65;0.60;0.60;0.75;0.90;0.75;0.60;0.60;0.75;0.95;0.75;0.60;0.60;0.65;0.75;0.65;0.60;0.60;0.65;0.90;0.65;0.60;0.60" 
    /> 
</image> 
<image class="layer letters" width="640" height="190" xlink:href="http://omnichron.net/external/op/src/meridian/letters.png" /> 

为了保护您的隐私SVG在图像上下文中使用时,必须是在一个文件中完成。

如果你想在SVG中有图像,你需要将它们编码为data URIs

+0

这样做。非常感谢。尽管我不得不说,那似乎是这种限制的愚蠢理由。他们试图保护什么?创作者可公开访问的网站地址?嘿。 – 2015-04-05 17:47:50

+0

为了方便任何其他人的参考,这里有一个在线URI编码器,它可以处理更大的图像(只需将原始输出复制到你的href中):http://www.askapache.com/online-tools/base64-image -converter/ – 2015-04-05 17:50:21

+0

如果您从网站上传图片,则不会期望该图片能够跟踪您。如果图像能够发出外部负载请求,那么可能发生这种情况。 – 2015-04-05 21:24:41