<feDisplacementMap>

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Das <feDisplacementMap> SVG Filter-Primitive verwendet die Pixelwerte des Bildes von in2, um das Bild von in räumlich zu verschieben.

Die Formel für die Transformation sieht folgendermaßen aus:

P'(x,y) ← P(x + scale * (XC(x,y) - 0.5), y + scale * (YC(x,y) - 0.5))

wobei P(x,y) das Eingabebild, in, ist und P'(x,y) das Ziel darstellt. XC(x,y) und YC(x,y) sind die Komponentenwerte des Kanals, der durch xChannelSelector und yChannelSelector bestimmt wird.

Wie andere Filter-Primitives behandelt es Farbkomponenten standardmäßig im linearRGB Farbraum. Sie können color-interpolation-filters verwenden, um stattdessen sRGB zu verwenden.

Verwendungskontext

KategorienPrimitives Filterelement
Erlaubter InhaltBeliebige Anzahl folgender Elemente, in beliebiger Reihenfolge:
<animate>, <discard>, <set>

Attribute

DOM-Schnittstelle

Dieses Element implementiert die SVGFEDisplacementMapElement Schnittstelle.

Beispiel

html
<svg
  width="200"
  height="200"
  viewBox="0 0 220 220"
  xmlns="http://www.w3.org/2000/svg">
  <filter id="displacementFilter">
    <feTurbulence
      type="turbulence"
      baseFrequency="0.05"
      numOctaves="2"
      result="turbulence" />
    <feDisplacementMap
      in2="turbulence"
      in="SourceGraphic"
      scale="50"
      xChannelSelector="R"
      yChannelSelector="G" />
  </filter>

  <circle cx="100" cy="100" r="100" style="filter: url(#displacementFilter)" />
</svg>

Spezifikationen

Specification
Filter Effects Module Level 1
# feDisplacementMapElement

Browser-Kompatibilität

Siehe auch