How to Convert Images to TIFF Format using C# .NET Framework
Converting images to TIFF is an easy way to retain sharp image quality. Writing the code to make that conversion can be a bit tricky, however.
Thankfully, using the ready-to-run code examples below, we can easily take advantage of a free API to make TIFF conversions easy. We can use this service as a one-size-fits-all solution to convert dozens of unique image file formats (including JPG, PNG, and even PDF) to TIFF format, and we can make this conversion up to 800 times per month with a free API key.
To structure our API call, let’s start by installing the SDK. We can install via NuGet by running this command in our Package Manager console:
Install-Package Cloudmersive.APIClient.NET.ImageRecognition -Version 3.0.5
Next, we can call the function using the below code examples. Let’s copy our API key into the appropriate parameter & load our file in for a multipart/form-data request:
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 ConvertToTiffExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertApi();
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
{
// Convert input image to TIFF format
byte[] result = apiInstance.ConvertToTiff(imageFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertApi.ConvertToTiff: " + e.Message );
}
}
}
}
That’s all there is to it — now we can easily convert a wide range of image formats to TIFF format with a single API solution.