This GitHub gist repository contains practical C# code snippets from the Working With SVG Colors in C# chapter of Aspose.SVG for .NET documentation. These practical snippets demonstrate how to programmatically manipulate background and element colors in SVG documents.
- Add Background Color – Insert a
<rect>element with a fill color behind existing SVG content. - Apply Background Color with CSS – Use internal CSS
<style>element with a CSS class to color the SVG background. - Recolor Elements – Change colors for a background and for content elements.
- Change Background Color – Change the
fillattribute value of existing<rect>element that serves as a background. - Adjust Line and Circle Colors – Update colors for SVG elements like
<line>or<circle>programmatically. - Apply Script for Background Color – Append a
<script>element to dynamically add a background rectangle via JavaScript. - Convert HEX to RGB – Parse HEX color strings and convert them to RGB format.
- Create a C# project and add the Aspose.SVG for .NET package via NuGet.
- Find the gist that corresponds to your specific task. Copy the C# code directly from the gist.
- Adjust file paths, input, and output parameters as needed.
- Run the code to review the output SVG files in your browser or image viewer to verify applied color changes.
You can download a free trial of Aspose.HTML for .NET and use a temporary license for unrestricted access.
Aspose.SVG for .NET is a cross-platform C# library for creating, editing, and rendering SVG files, ideal for applications on Windows, Linux, and macOS. It provides full support for vector graphics through the DOM API, allowing you to control background fills, element strokes, CSS-based styling, and even dynamic scripts. Built-in color analysis functions simplify workflows that require converting color codes, for example, from hex values to RGB and etc.
- Documentation – Aspose.SVG for .NET
- API Reference – Aspose.SVG for .NET
- Product page – Aspose.SVG for .NET
- Blog – Aspose.SVG Product Family
- Temporary License
- Free Online Color Converters – Aspose.SVG
- .NET Platforms: .NET Framework 4.6.1+, .NET Core 2.0+, or .NET 5.
- Supported OS: Windows, Linux, macOS.
- Development environment such as Visual Studio or JetBrains Rider.
- Aspose.SVG for .NET installed via NuGet.