How to Convert Images to Bitmap Format using C# .NET Framework

Cloudmersive
2 min readFeb 5, 2024

--

If we’re looking to simplify our process for converting images to Bitmap format, we can leverage a low-code API solution and avoid writing lots of code ourselves.

Conveniently, using the ready-to-run C# code provided below, we can take advantage of a free API right away to convert 100+ unique image formats to Bitmap format. All we need to do is acquire a free API key (allowing 800 API calls per month with no commitments) and follow two quick steps to install the SDK & call the function.

To install the SDK via NuGet, let’s go ahead and run the following command in our Package Manager console:

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

To call the function, let’s now copy the below code examples into our file (remembering to include our API key string for authorization):

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 ConvertToBmpExample
{
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 Bitmap BMP format
byte[] result = apiInstance.ConvertToBmp(imageFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertApi.ConvertToBmp: " + e.Message );
}
}
}
}

This service will automatically detect incoming formats and return Bitmap versions of those files in short order.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet