Coordinate systems are important while working with graphics and shapes. The coordinate axis can be rotated for obtaining new axes through the same origin. Let us explore the following transformations including Matrix, Global, Local, and World transformation using C# language. Moreover, let us learn the following transformations through this article:
- Matrix, Global, Local and World Transformation – C# API Installation
- Apply Matrix Transformation Programmatically using C#
- Apply Global Coordinate Transformation Programmatically with C#
- Set Local Transformation Programmatically in C#
- Apply World Transformation Programmatically using C#
Matrix, Global, Local and World Transformation – C# API Installation
Aspose.Drawing for .NET API supports processing different drawing objects. You can easily create, edit, transform, or render graphics in your .NET-based applications. Simply download the DLL file from the New Releases section. On the other hand, you can configure it from NuGet with the following installation command:
PM> Install-Package Aspose.Drawing
Apply Matrix Transformation Programmatically using C#
The Matrix class has a 3 by 3 affine matrix which represents the transformation. You can use it to Rotate, Translate, or Scale a shape as per your requirements. The following steps explain how to apply matrix transformation:
- Instantiate Bitmap class object
- Create a shape
- Apply Matrix transformation
The code below shows how to apply matrix transformation programmatically using C# language:
Apply Global Coordinate Transformation Programmatically with C#
Global transformation is used to transform all graphical objects in a drawing. You can follow the steps below for applying global coordinate transformation:
- Initialize an instance of Bitmap class
- Declare Graphics class object
- Set rotation
- Draw a shape with Global Transformation
The following code elaborates global coordinate transformation programmatically using C#:
Set Local Transformation Programmatically in C#
Local transformation is related to specific shapes or graphics in a drawing. It can be explained with transformation of a graphics path where only the items of that path are transformed. You can set local transformation with the following steps:
- Initialize an object of Bitmap class
- Declare Graphics and GraphicsPath class object
- Create a shape and define Matrix
- Call Transform method
The code snippet below explains how to set local transformation programmatically using C#:
Apply World Transformation Programmatically using C#
The conversion of World coordinates to Page coordinates is known as World Transformation. Such page coordinates are then used for rendering graphics on different devices. So you can apply world transformation using C# with the steps below:
- Initialize an object of the Bitmap class
- Call TranslateTransform method
- Draw a shape
The following code shows how to apply world transformation programmatically using C# language:
Conclusion
In a nutshell, you have learned about different transformations related to computer graphics and shapes. You must be able to understand the details of Global, Local, and World transformation using the C# language. Furthermore, you may read the API Documentation for more details or get in touch with us via the Free Support Forums. We would love to help you!