How to rotate an image a set number of degrees in C# .NET Framework

Cloudmersive
2 min readFeb 2, 2020

--

Image rotation should be a piece of cake right? Well, the conventional method for setting this up is actually a bit of a hassle. For today, we will instead be taking a nice shortcut to skip you straight to the results.

Our initial step is to install our API Client. We can do this via NuGet by pasting the following line into Package Manager console.

Install-Package Cloudmersive.APIClient.NET.ImageRecognition -Version 2.1.1

Now call EditRotate and specify how many degrees (0–360) you would like to rotate the image:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.ImageRecognition.Api;using Cloudmersive.APIClient.NET.ImageRecognition.Client;using Cloudmersive.APIClient.NET.ImageRecognition.Model;namespace Example{public class EditRotateExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");var apiInstance = new EditApi();var degrees = 1.2;  // double? | Degrees to rotate the image; values range from 0.0 to 360.0.var imageFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.try{// Rotate an image any number of degreesbyte[] result = apiInstance.EditRotate(degrees, imageFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditApi.EditRotate: " + e.Message );}}}}

And that’s really all there is to it. Our image will be returned to us in its rotated form, ready to go.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet