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

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.

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store