我在GUI中顯示圖像並應用了SVG過濾器。現在我的要求是通過轉換爲二進制或base64來保存這個已更改的圖像[應用了SVG過濾器]。我試圖使用畫布轉換。但無法實現。這是我迄今爲止所嘗試的。任何人都可以提供一些提示繼續。將SVG過濾器應用的圖像轉換爲二進制或base64以保存在後端
<div class="item active filtered" data-slide-number="0">
<svg style="overflow: hidden; height: 637px; width: 546px;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">
<defs>
<filter id="svgBlur" width="110%" height="110%">
<feComponentTransfer id="bFilter">
<feFuncR id="brightness1" class="brgt" type="linear" slope="2"></feFuncR>
<feFuncG id="brightness2" class="brgt" type="linear" slope="1"></feFuncG>
<feFuncB id="brightness3" class="brgt" type="linear" slope="1"></feFuncB>
</feComponentTransfer>
<feComponentTransfer id="cFilter">
<feFuncR id="contrast1" class="cnst" type="linear" slope="1" intercept="-0.01"></feFuncR>
<feFuncG id="contrast2" class="cnst" type="linear" slope="1" intercept="-0.01"></feFuncG>
<feFuncB id="contrast3" class="cnst" type="linear" slope="1" intercept="-0.01"></feFuncB>
</feComponentTransfer>
<feComponentTransfer id="gFilter">
<feFuncR id="gamma1" class="gama" type="gamma" amplitude="1" exponent="1" offset="0"></feFuncR>
<feFuncG id="gamma2" class="gama" type="gamma" amplitude="1" exponent="1" offset="0"></feFuncG>
<feFuncB id="gamma3" class="gama" type="gamma" amplitude="1" exponent="1" offset="0"></feFuncB>
</feComponentTransfer>
<feColorMatrix id="saturation" type="saturate" values="1"></feColorMatrix>
</filter>
</defs>
<g id="viewport-20160404045307934" class="svg-pan-zoom_viewport" transform="matrix(1.011111111111111,0,0,1.011111111111111,2.52222222222224,0)">
<image xlink:href="https://www.ricoh.com/r_dc/caplio/r7/img/sample_03.jpg" class="img-responsive" width="90%" id="imageStyling" height="630px" style="height: 630px; width: 536px;" filter="url(#svgBlur)" name="ipsDF14-2-29Feb16-9d80-1a94a2e8c121"></image>
</g>
</svg>
</div>
<button id="save">Save</button>
<canvas id="canvas"></canvas>
$(document).ready(function() {
var btn = document.querySelector('button');
var svg = document.querySelector('svg');
var canvas = document.querySelector('canvas');
$("#save").click(function() {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var data = (new XMLSerializer()).serializeToString(svg);
var DOMURL = window.URL || window.webkitURL || window;
var img = new Image();
var svgBlob = new Blob([data], {
type: 'image/svg+xml;charset=utf-8'
});
var url = DOMURL.createObjectURL(svgBlob);
alert(JSON.stringify(url));
})
});
非常感謝您的詳細信息。去選擇選項3.快樂編碼:) – Nofi
對於選項1,我寫了[此腳本](https://github.com/Kaiido/SVG2Bitmap),它將處理大多數可訪問的外部資源,並在它返回之前將其實施到svg中畫在畫布上。儘管如此,IE <邊緣限制也適用,但對於這些瀏覽器,只需右鍵單擊svg +'另存爲... * .png'即可。對於選項2,Webkit瀏覽器確實在'實驗畫布特徵「標誌下實現了一些(至少是blur(),'saturate()','url()'!),yeeha實時GPU加速篩選來了!不幸的是,選項3仍然是唯一的跨瀏覽器。 – Kaiido