How to Rotate an SVG in C#

This article guides on how to rotate an SVG in C#. It has all the details to set the environment, a list of tasks to be performed while developing the application and a runnable sample code for SVG rotate in C#. You will learn the creation of the source SVG file and then rotation of the line element in it.

Steps to Rotate an SVG in C#

  1. Set the environment to use Aspose.SVG for .NET for rotating an SVG
  2. Prepare a string for an SVG file with a line in it
  3. Instantiate an SVGDocument object using the specified string
  4. Get the RootElement of the SVGDocument and select the line element in it
  5. Set the transform attribute for the line after saving the intermediate SVG file
  6. Save the output SVG file with a rotated line

These steps describe the process of how to rotate SVG image in C#. The process is commenced by creating an SVG file with a line in it followed by accessing the line element from it, however, you may load an existing SVG file. An intermediate SVG file is saved on the disk before setting the transform attribute for rotating the line and then the resultant file is saved on the disk.

Code to Rotate SVG Image in C#

This code snippet has demonstrated the task of SVG rotate in C#. This code segment uses the QuerySelector() method to select the target shape that is to be rotated. The rotate() method is used that takes the angle by which the rotation is to be done followed by the coordinates of the point around which rotation is to be performed.

This article has taught us to rotate a line in an SVG file. If you want to learn the process to convert an SVG file to an image, refer to the article on how to convert SVG to image in C#.

 English