Cod*_*ust 2 html matrix svg-filters
每个 feColorMatrix 值的含义是什么?
我有一个黑色的 svg 形状,它必须用 #26bf8c 颜色遮盖。我想找到该矩阵的含义以将我的十六进制转换为它?
<svg width='20px' height='10px' preserveAspectRatio='none meet'>
<image filter='url(#colorMatrixFilter1)' width='20px' height='10px' xlink:href='../img.svg' />
<defs>
<filter id='colorMatrixFilter1'>
<feColorMatrix type='matrix'
values='1 0 0 0 0
1 0 0 1 0
1 0 0 0 0
0 1 0 1 0
'/>
</filter>
</defs>
</svg>
Run Code Online (Sandbox Code Playgroud)
我以为我可以写下 RGB 值作为它们的二进制表示,但矩阵似乎以不同的方式工作。
要将元素重新着色为特定颜色,您必须执行此操作。
你的具体矩阵是:
<filter id='colorMatrixFilter1' color-interpolation-filters="sRGB">
<feColorMatrix type='matrix'
values='0 0 0 0 0.149
0 0 0 0 0.749
0 0 0 0 0.548
0 0 0 1 0'/>
</filter>
Run Code Online (Sandbox Code Playgroud)
前四列中的所有值都是乘数。它们获取每个像素的每个颜色通道的值,将其乘以该矩阵单元的值,然后将其添加到另一个颜色通道。第五列是偏移量 - 它为每个颜色通道添加一个固定值。
矩阵的单元格 1,1 是红色 -> 红色乘数
矩阵的单元格 2,1 是绿色 -> 红色乘数(以列、行表示法)
矩阵的单元格 1,2 是红色 -> 绿色乘数(以列、行表示法表示)等。
要查看每个单元格的作用 - 您可以在此处使用实时颜色矩阵: https: //beta.observablehq.com/@gitmullany/filter-effects-using-svg-color-matrices