SVG images are getting popular because of their scalability and quality features. In some scenarios, you might need to change the color of SVG images to make them more attractive. This article covers how to change the color of different SVG elements programmatically in C#.
- Work with the Color of SVG Elements – C# .NET API Installation
- Change the Color of Circle Element of SVG in C#
- Change the Color of Line Element of SVG in C#
- Set the Background Color of SVG Image in C#
Work with the Color of SVG Elements – C# .NET API Installation
You can manipulate the color of different SVG elements like Circle, Line, etc. with Aspose.SVG for .NET API. Simply download the DLL files from the New Releases, or use the following NuGet installation command:
PM> Install-Package Aspose.SVG
Change the Color of Circle Element of SVG in C#
You can change the color of the circle element of SVG in C# with the following steps:
- Create an instance of SVGDocument class to load the input SVG file.
- Get root and circle SVG element of the document.
- Set attribute and color for the SVG element.
- Save the output SVG image.
The code snippet below elaborates how to change the color of the circle element of SVG in C#:
Change the Color of Line Element of SVG in C#
Please follow the steps below for changing the color of the Line element in an SVG image in C#:
- Initialize an object of SVGDocument class to load the source SVG image.
- Get root and line element to modify the color.
- Save the output SVG file using the Save method.
The following code snippet shows how to change line color in SVG file programmatically in C#:
Set the Background Color of SVG Image in C#
You can enhance the appearances of SVG images by setting the background color of SVG images with the following steps:
- Set SVG namespace and load the input file.
- Create a rectangle element and set different properties.
- Add rectangle element as first child and save output file.
The code snippet below demonstrates how to set the background color of SVG image programmatically in C#:
Get Free Evaluation License
You can evaluate the API without any evaluation limitations by getting a free evaluation license.
Conclusion
In this article, you have learned how to change the color of different elements in an SVG image. Likewise, the details about setting the background color of an SVG image are also discussed here. Moreover, you can take a look at other features of the API in the documentation section. In case of any queries, please write to us at the forum.