Created
September 20, 2022 07:16
-
-
Save aspose-com-gists/d412107867fb36aad80a35bd6bda9db7 to your computer and use it in GitHub Desktop.
Create Gaussian Blur Filter on SVG in C# | feGaussianBlur Effect on Scalable Vector Graphics in .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize a SVGDocument class object | |
Aspose.Svg.SVGDocument document = new Aspose.Svg.SVGDocument("complex.svg"); | |
// Set SVG Namespace Url | |
string SvgNamespace = "http://www.w3.org/2000/svg"; | |
// Get root svg element of the document | |
Aspose.Svg.SVGSVGElement svgElement = document.RootElement; | |
// Create an image element and add it to the svgElement | |
Aspose.Svg.SVGImageElement imageElement = (Aspose.Svg.SVGImageElement)document.CreateElementNS(SvgNamespace, "image"); | |
imageElement.Href.BaseVal = dataDir + "complex.jpg"; | |
imageElement.Height.BaseVal.ConvertToSpecifiedUnits(Aspose.Svg.DataTypes.SVGLength.SVG_LENGTHTYPE_PX); | |
imageElement.Width.BaseVal.ConvertToSpecifiedUnits(Aspose.Svg.DataTypes.SVGLength.SVG_LENGTHTYPE_PX); | |
imageElement.Height.BaseVal.Value = 640; | |
imageElement.Width.BaseVal.Value = 480; | |
imageElement.X.BaseVal.Value = 20; | |
imageElement.Y.BaseVal.Value = 20; | |
imageElement.SetAttribute("filter", "url(#F1)"); | |
svgElement.AppendChild(imageElement); | |
// Create a defs element and add to the svgElement | |
Aspose.Svg.SVGDefsElement defsElement = (Aspose.Svg.SVGDefsElement)document.CreateElementNS(SvgNamespace, "defs"); | |
svgElement.AppendChild(defsElement); | |
// Create a filter element and add to the defsElement | |
Aspose.Svg.SVGFilterElement filterElement = (Aspose.Svg.SVGFilterElement)document.CreateElementNS(SvgNamespace, "filter"); | |
defsElement.AppendChild(filterElement); | |
// Create a feGaussianBlur element and add to the filterElement | |
Aspose.Svg.Filters.SVGFEGaussianBlurElement feGaussianBlurElement = (Aspose.Svg.Filters.SVGFEGaussianBlurElement)document.CreateElementNS(SvgNamespace, "feGaussianBlur"); | |
feGaussianBlurElement.In1.BaseVal = "SourceGraphic"; | |
feGaussianBlurElement.StdDeviationX.BaseVal = 3; | |
feGaussianBlurElement.StdDeviationY.BaseVal = 3; | |
feGaussianBlurElement.SetAttribute("x", "-20px"); | |
feGaussianBlurElement.SetAttribute("y", "-20px"); | |
feGaussianBlurElement.SetAttribute("height", "720px"); | |
feGaussianBlurElement.SetAttribute("width", "560px"); | |
filterElement.Id = "F1"; | |
filterElement.AppendChild(feGaussianBlurElement); | |
// Save the SVG document | |
document.Save(Path.Combine(dataDir, "gaussianBlur.svg")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment